Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,15 @@
use strict;
use warnings;
use feature 'say';
use Heap::Priority;
my $h = Heap::Priority->new;
$h->highest_first(); # higher or lower number is more important
$h->add(@$_) for ["Clear drains", 3],
["Feed cat", 4],
["Make tea", 5],
["Solve RC tasks", 1],
["Tax return", 2];
say while ($_ = $h->pop);

View file

@ -0,0 +1,31 @@
use strict;
use warnings; # in homage to IBM card sorters :)
my $data = <<END;
Priority Task
3 Clear drains
4 Feed cat
5 Make tea
1 Solve RC tasks
2 Tax return
4 Feed dog
END
insert( $1, $2 ) while $data =~ /(\d+)\h+(.*)/g; # insert all data
while( my $item = top_item_removal() ) # get in priority order
{
print "$item\n";
}
######################################################################
my @bins; # priorities limited to small (<1e6 maybe?) non-negative integers
sub insert { push @{ $bins[shift] }, pop } # O(1)
sub top_item_removal # O(1) (sort of, maybe?)
{
delete $bins[-1] while @bins and @{ $bins[-1] // [] } == 0;
shift @{ $bins[-1] // [] };
}