Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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! )


In reply to Re: Challenge: Egg Timer Puzzles by ikegami
in thread Challenge: Egg Timer Puzzles by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (4)
    As of 2020-01-18 20:01 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?