in reply to Time Allotments

A valid start would be "a, b, c, d, a, b, c, e, a, b, c, f, a, b, c, g, a, b, c, h, a, b, c, d..." etc, though 'd' was forced to be refreshed on the 21st second because of upcoming 'a' 'b' and 'c's.

What does "refreshed" mean ? And 21st?

 

Some observations

Hmm, it seems obvious you should give priority to shortest max, and give priority to anything approaching max/2

Graph theory comes to mind ... and tetris , no, PONG , tk widget demo , Balls bouncing in a cavity

Keeps the balls from touching down by smacking them up, a,b,c would be very heavy, the hardest hit you can deliver only keeps them airborne 4 seconds, where k is a hot air baloon ,

Replies are listed 'Best First'.
Re^2: Time Allotments
by alanonymous (Sexton) on Feb 19, 2012 at 06:50 UTC
    I think you're on the right track with hitting balls up for 4 sec, etc ... a good way to visualize and think through it.

    If you count out the letters from the example above of "a, b, c, d, a, b, c, e..." etc, the second 'd' event comes prematurely after 21 seconds instead of after 24 to abide by the rule and still allow the a, b, c to still occur at the right interval, otherwise it would have been 25 seconds if a, b, c repeated again prior to the 2nd 'd'. Does that explain it?

      Does that explain it?

      Yes, it makes sense now, after playing with this. You say refreshed, I say reset/reinitialized.

      #!/usr/bin/perl -- use strict; use warnings; use Tk; my %in = ( a => 4, # HEAVY b => 4, c => 4, d => 24, e => 24, f => 24, g => 1000, h => 150, i => 150, j => 150, k => 600, # hot air baloon ); my @ev11 = map {[$_, $in{$_}, 0, $in{$_}, undef ]} sort keys %in; my $mw = tkinit; my $fr = $mw->Frame( -background => 'red', )->pack;#( qw/ -expand x -f +ill x -anchor n -side top / ); $fr->Label( -text => 'NUMHITS:')->grid( qw/ -stick ew -row 1 -column 1 + /); $fr->Label( -text => 'letter(interval):')->grid( qw/ -stick ew -row 2 +-column 1 /); $fr->Label( -text => 'time remaining:')->grid( qw/ -stick ew -row 3 -c +olumn 1 /); my %butt; { #~ $one->[0] letter #~ $one->[1] interval #~ $one->[2] number hits #~ $one->[3] time remaining #~ $one->[4] button use constant INTERVAL => 1; use constant NUMHITS => 2; use constant TIMEREM => 3; use constant BUTTON => 4; my $col = 2; for my $one ( @ev11 ){ $fr->Label( -relief => 'groove', -text => $one->[0] . ' (' . $one->[1] . ')', )->grid( qw/ -sticky ew -row 2 /, -column => $col ); $fr->Label( -relief => 'groove', -textvariable => \$one->[NUMHITS] )->grid( qw/ -sticky ew -row 1 /, -column => $col ); $one->[BUTTON] = $fr->Button( -command => \&Fooo, -textvariable => \$one->[TIMEREM], )->grid( qw/ -sticky ew -row 3 /, -column => $col ); $col++; $butt{ $one->[BUTTON] } = $one; } } my $tx = $mw->ROText->pack(qw/ -expand 1 -fill both -anchor n -side to +p / ); MainLoop; sub Fooo { my $b = $Tk::event->W; $tx->insert( 'end', sprintf '%s(%d/%d), ', $butt{ $b }->[0] , $butt{ $b }->[NUMHITS] , $butt{ $b }->[TIMEREM], ); for my $one ( @ev11 ){ $one->[TIMEREM]--; $one->[BUTTON]->configure( qw/ -state normal /); } $butt{ $b }->[NUMHITS]++; $butt{ $b }->[TIMEREM] = $butt{ $b }->[INTERVAL]; $b->configure( qw/ -state disabled /) ; } __END__

      a(0/4), b(0/3), c(0/2), a(1/2), b(1/2), c(1/2), d(0/18), a(2/1), b(2/1), c(2/1), e(0/14), a(3/1), b(3/1), c(3/1), f(0/10), a(4/1), b(4/1), c(4/1),

      Looks like you could have four 4-second repeaters max without dropping one ( or five 4 second repeaters and nothing else).

        Your code is going to take me a few minutes to digest :)