Skip to content

Instantly share code, notes, and snippets.

/euros.pl6 Secret

Created June 9, 2016 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/af60e979bfa4df3a33b1ed99e84f6b68 to your computer and use it in GitHub Desktop.
Save anonymous/af60e979bfa4df3a33b1ed99e84f6b68 to your computer and use it in GitHub Desktop.
random euros allocations
#!/usr/bin/env perl6
role Decorator {
method dump(){
#say $!allocations;
#for $.allocations.kv -> $k,$v {
# say "$k - " ~ $v.join(" - ");
#}
}
}
class Allocator does Decorator {
has $.POT_1 is rw = qw|France Germany Spain England Belgium Italy Portugal Croatia Poland Austria Switzerland Russia|.map({ $_ => $_ }).Hash;
has $.POT_2 is rw = qw|Turkey Ukraine Wales Iceland Sweden Czech_Republic Romania Republic_of_Ireland Slovakia Hungary Albania Northern_Ireland|.map({ $_ => $_ }).Hash;
has $.users = qw|Matt_W Dan_S Kate_D Pete_K Samantha_C Mo_R Declan_T Natalie_S Tara_K Arda_T Dave_C Mahdi_M Aaron_F|.map({ $_ => $_}).Hash;
has $.allocations;
multi method allocate(){
loop {
my $selected_user = $!users.keys.pick; $!users{$selected_user}:delete;
## get from POT 1
my $selected_POT1 = $!POT_1.keys.pick; $!POT_1{$selected_POT1}:delete;
## get from POT 2
my $selected_POT2 = $!POT_2.keys.pick; $!POT_2{$selected_POT2}:delete;
$!allocations{$selected_user} = [$selected_POT0, $selected_POT2];
last if ( !$!users.Int );
}
self
}
method dump(){
for $.allocations.kv -> $k,$v {
say "$k - " ~ $v.join(" - ");
}
}
}
### main
Allocator.new.allocate().dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment