Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Challenge: Egg Timer Puzzles

by ikegami (Patriarch)
on May 03, 2006 at 05:27 UTC ( [id://547060]=note: print w/replies, xml ) Need Help??


in reply to Challenge: Egg Timer Puzzles

Here's a very straightforward version that implements
"given a 7-min timer & a 4-min egg timer"
rather than
"given unlimited 7-min timers & unlimited 4-min egg timers
It's unclear what the OP intended.

use List::Util qw( min ); use List::MoreUtils qw( any ); my $target = 5; my @max = (7, 4); my $time = 0; my @status = (0) x @max; my %seen; for (;;) { die("Unable to solve the problem\n") if $seen{join('|', @status)}++; foreach (0..$#status) { next if $status[$_]; $status[$_] = $max[$_]; print("$time: begin $max[$_]\n"); } last if any { $_ == $target } @status; my $elapsed_time = min(@status); $status[$_] = $status[$_] - $elapsed_time foreach 0..$#status; $time += $elapsed_time; } print("$time: begin cooking\n"); $time += $target; print("$time: end cooking\n");
outputs
0: begin 7 0: begin 4 4: begin 4 7: begin 7 8: begin 4 12: begin 4 14: begin 7 16: begin 4 16: begin cooking 21: end cooking

I don't support putting the timer's on hold, but that's just laziness on my end :)

.oO( Why aren't Scalar::Util, List::Util and List::MoreUtils core modules? I wouldn't mind if the function in those modules were core functions! )

Replies are listed 'Best First'.
Re^2: Challenge: Egg Timer Puzzles
by Limbic~Region (Chancellor) on May 03, 2006 at 13:05 UTC
    ikegami,
    It's unclear what the OP intended.

    Indeed. I updated the root thread to reflect my intentions though I still want people to be able to intepret the puzzle any way they want. These are fun distractions that I like to post and aren't intended to be right or wrong.

    Thanks for your contribution. Compare your solution to my by hand solution for a 20 minute target with 3/5/13/19 egg timers.

    3 5 13 19 Step1. 3 & 5 together (elapsed time 3 minutes) 3 2/3 13 19 Step2. 3 & 13 together (elapsed time 6 minutes) 3 2/3 3/10 19 Step3. 10 & 19 together (elapsed time 16 minutes) 3 2/3 13 9/10 Step4. 2 & 9 together (elapsed time 18 minutes) 3 5 13 7/12 Step5. Begin cooking & start 13 (elapsed time 31 minutes) 3 5 13 7/12 Step6. start 7 (elapsed time 38 minutes) 3 5 13 19 Step7. Finish cooking 38 - 18 = 20
    Also see where yours fails for 21.
    3 5 13 19 Step1 A. Begin cooking & start 19 (elapsed time 19 minutes) Step1 B. Simultaneously start 3 & 5 (no change to elapsed time) 3 2/3 13 19 Step2. Start 2 (elapsed time 21 minutes) Step3. Finish cooking
    Of course, you could run this end to end where the 3/5 is done first to get to the 2 minutes and then start the 19 but that would exceed 21 minutes. I think a nice variation on this puzzle would be to limit the overall amount of time you have to cook the egg. This might force the "setting aside" intermediate timers while longer timers are running.

    Cheers - L~R

      Oops, I forgot to mention it was only mean to work for times smaller than the maximum egg timer time (or is it smaller than the minimum eff timer time?) It was just an initial try.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://547060]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2024-04-18 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found