This week's Car Talk puzzler solution using SPSS

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

This week's Car Talk puzzler solution using SPSS

Hal 9000
Hi List,

For those of you who enjoy the NPR radio show "Car Talk," you know
they have a weekly puzzle. For those of you who are not familiar with
it, you can still enjoy the puzzle below.

(Disinterested, please ignore...this is just a one-time posting).

I use SPSS for problems that I can't easily solve with a pen and
paper. I have solved past Car Talk puzzlers with SPSS, but this one
was especially fun, and I thought I'd share it with you. Constructive
criticism is welcome.

The original puzzle is pasted verbatim at the start. The answer is at
the end, so don't look if you prefer to solve it yourself - Enjoy!
-Gary



* 3.23.08
* This Week's Car Talk Puzzler:
* An Age-Old Question about a Ship and Its Boiler

* RAY:  This is from my shipping series and it was
  sent in by Fred Gluck. He writes: "Back in the old
  days ships of yesteryear were driven by steam and
  it was often the case that the ship would outlive
  the engine and the boiler and they'd have to replace them.

* "Now, take one ship for example. When you add the age
  of the ship and the age of its boiler, it totals 42
  years. So S + B = 42. Now pay attention! The ship is
  twice as old as the boiler was when the ship was as
  old as the boiler is now."

* The question is how old are they?

*************** start syntax ****************************.

input program.
loop #X = 1 to 42.
loop #Y = 1 to 42.
compute S_now = #X.
compute b_now = #Y.
end case.
end loop.
end loop.
end file.
end input program.

* the ship is at least as old as the boiler,
  and we only care about combinations that
  sum to 42.

select if b_now le s_now & s_now + b_now = 42.

vector s_then (42).
vector b_then (42).
loop #T = 1 to 42.
compute s_then(#T) = #T.
compute b_then(#T) = #T.
end loop.

variable labels
         s_now 'Ship Age Now'
        /b_now 'Boiler Age Now'
        /s_then1 'Ship Age Then - 1st Permutation'
        /b_then1 'Boiler Age Then - 1st Permutation'.

* investigate all permutations - aren't loops nice?.

loop #S = 1 to 42.
loop #B = 1 to 42.
compute flag =
        s_now = 2 * b_then(#B) &
        b_now = s_then(#S).
compute idx_s = #S.
compute idx_b = #B.
end loop if flag = 1.
end loop if flag = 1.

* eliminate logically invalid permutations: .

select if
        flag &
        idx_s gt idx_b &
        mod(idx_s + idx_b,2) = 0.

list s_now b_now idx_s idx_b.
exe.

*
*
*
*
*
*
*
*
*
*
*
*
*
* Answer:                  (S_THEN)(B_THEN)
        S_NOW
B_NOW    IDX_S   IDX_B
        24.00       18.00       18.00    12.00  .


* That was fun! .

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: This week's Car Talk puzzler solution using SPSS

Hal 9000
Mark,

Good point. It's ironic that using SPSS was far more difficult and
time consuming than approaching it fairly (algebraically). You've
exposed my secret joy in being a creative cheater. At every turn, I
disallowed myself to think algebraically, which was strangely fun.

It's a bone-headed way to do it, but I wanted to challenge
myself...It's good for the synapses, at least. I initially started
with a 'tall' data structure for exploring permutations using the lag
function (that just about killed my cpu) and found the 'wide' approach
far more efficient. I enjoy running into those little kinks & trying
to understand them. Enjoy next week's show!

Take care,
-Gary


On Thu, Mar 27, 2008 at 10:44 AM, Mark A Davenport MADAVENP
<[hidden email]> wrote:

>
> I would suggest that using SPSS to solve the puzzler was cheating.  Then
> again, we are talking about Car Talk.  They will probably give you 2 Car
> Talk CD's just for being imaginitive.
>
> ***************************************************************************************************************************************************************
>  Mark A. Davenport Ph.D.
>  Senior Research Analyst
>  Office of Institutional Research
>  The University of North Carolina at Greensboro
>  336.256.0395
>  [hidden email]
>
>  'An approximate answer to the right question is worth a good deal more than
> an exact answer to an approximate question.' --a paraphrase of J. W. Tukey
> (1962)
>
>
>
>
>
>
>  Hal 9000 <[hidden email]>
> Sent by: "SPSSX(r) Discussion" <[hidden email]>
>
> 03/26/2008 06:39 PM
>
> Please respond to
>  Hal 9000 <[hidden email]>
>
>
> To
> [hidden email]
>
> cc
>
>
> Subject This week's Car Talk puzzler solution using SPSS
>
>
>
>
>
>
> Hi List,
>
>  For those of you who enjoy the NPR radio show "Car Talk," you know
>  they have a weekly puzzle. For those of you who are not familiar with
>  it, you can still enjoy the puzzle below.
>
>  (Disinterested, please ignore...this is just a one-time posting).
>
>  I use SPSS for problems that I can't easily solve with a pen and
>  paper. I have solved past Car Talk puzzlers with SPSS, but this one
>  was especially fun, and I thought I'd share it with you. Constructive
>  criticism is welcome.
>
>  The original puzzle is pasted verbatim at the start. The answer is at
>  the end, so don't look if you prefer to solve it yourself - Enjoy!
>  -Gary
>
>
>
>  * 3.23.08
>  * This Week's Car Talk Puzzler:
>  * An Age-Old Question about a Ship and Its Boiler
>
>  * RAY:  This is from my shipping series and it was
>   sent in by Fred Gluck. He writes: "Back in the old
>   days ships of yesteryear were driven by steam and
>   it was often the case that the ship would outlive
>   the engine and the boiler and they'd have to replace them.
>
>  * "Now, take one ship for example. When you add the age
>   of the ship and the age of its boiler, it totals 42
>   years. So S + B = 42. Now pay attention! The ship is
>   twice as old as the boiler was when the ship was as
>   old as the boiler is now."
>
>  * The question is how old are they?
>
>  *************** start syntax ****************************.
>
>  input program.
>  loop #X = 1 to 42.
>  loop #Y = 1 to 42.
>  compute S_now = #X.
>  compute b_now = #Y.
>  end case.
>  end loop.
>  end loop.
>  end file.
>  end input program.
>
>  * the ship is at least as old as the boiler,
>   and we only care about combinations that
>   sum to 42.
>
>  select if b_now le s_now & s_now + b_now = 42.
>
>  vector s_then (42).
>  vector b_then (42).
>  loop #T = 1 to 42.
>  compute s_then(#T) = #T.
>  compute b_then(#T) = #T.
>  end loop.
>
>  variable labels
>          s_now 'Ship Age Now'
>         /b_now 'Boiler Age Now'
>         /s_then1 'Ship Age Then - 1st Permutation'
>         /b_then1 'Boiler Age Then - 1st Permutation'.
>
>  * investigate all permutations - aren't loops nice?.
>
>  loop #S = 1 to 42.
>  loop #B = 1 to 42.
>  compute flag =
>         s_now = 2 * b_then(#B) &
>         b_now = s_then(#S).
>  compute idx_s = #S.
>  compute idx_b = #B.
>  end loop if flag = 1.
>  end loop if flag = 1.
>
>  * eliminate logically invalid permutations: .
>
>  select if
>         flag &
>         idx_s gt idx_b &
>         mod(idx_s + idx_b,2) = 0.
>
>  list s_now b_now idx_s idx_b.
>  exe.
>
>  *
>  *
>  *
>  *
>  *
>  *
>  *
>  *
>  *
>  *
>  *
>  *
>  *
>  * Answer:                  (S_THEN)(B_THEN)
>         S_NOW
>  B_NOW    IDX_S   IDX_B
>         24.00       18.00       18.00    12.00  .
>
>
>  * That was fun! .
>
>  =====================
>  To manage your subscription to SPSSX-L, send a message to
>  [hidden email] (not to SPSSX-L), with no body text except the
>  command. To leave the list, send the command
>  SIGNOFF SPSSX-L
>  For a list of commands to manage subscriptions, send the command
>  INFO REFCARD
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: This week's Car Talk puzzler solution using SPSS

Hal 9000
...and this week's (far better suited to an SPSS solution):

* 03/30/08 Car Talk Puzzler Solution .

input program.
loop #A = 1 to 99.
loop #B = 1 to 99.
compute A = #A.
compute B = #B.
end case.
end loop.
end loop.
end file.
end input program.

select if
        a < b &
        b - a < 30 &
        b - a > 15 &
        a > 50.

select if
  substr(string(a,f2),1,1) = substr(string(b,f2),2,1) &
  substr(string(a,f2),2,1) = substr(string(b,f2),1,1).

compute ab_diff = b - a.
sort cases by ab_diff a.

* :) .

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD