Last active
September 24, 2015 20:38
-
-
Save abraxxa/806301 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
use v6; | |
say 'Willkommen bei EuroMillionen!'; | |
my %rank_for = %( | |
5 => { | |
2 => 1, | |
1 => 2, | |
0 => 3, | |
}, | |
4 => { | |
2 => 4, | |
1 => 5, | |
0 => 6, | |
}, | |
3 => { | |
2 => 7, | |
1 => 8, | |
0 => 10, | |
}, | |
2 => { | |
2 => 9, | |
1 => 12, | |
}, | |
1 => { | |
2 => 11, | |
} | |
); | |
my $play_again; | |
repeat { | |
until (my $input = prompt('Wollen sie einen Quicktipp abgeben? j/n: ')) ~~ any( "j", "n" ) {} | |
my $qtip = $input eq 'j'; | |
my @numbers; | |
my @stars; | |
# could use junction but need array for pick | |
my @allowed_numbers = (1..50); | |
my @allowed_stars = (1..9); | |
if ($qtip) { | |
@numbers = @allowed_numbers.pick(5); | |
@stars = @allowed_stars.pick(2); | |
} | |
else { | |
for 1..5 { | |
# ask again until one of the allowed numbers and none of the already chosen numbers | |
until (my $input = prompt("Bitte geben sie Nummer $_ ein (1-50): ")) ~~ any( @allowed_numbers ) && $input !~~ any @numbers {} | |
push @numbers, $input; | |
} | |
for 1..2 { | |
# ask again until one of the allowed stars and none of the already chosen stars | |
until (my $input = prompt("Bitte geben sie Stern $_ ein (1-9): ")) ~~ any( @allowed_stars ) && $input !~~ any @stars {} | |
push @stars, $input; | |
} | |
} | |
say "Ihr Tipp lautet: {@numbers.sort}, {@stars.sort}"; | |
my @drawn_numbers = @allowed_numbers.pick(5); | |
my @drawn_stars = @allowed_stars.pick(2); | |
say "Die gezogenen Nummern und Sterne lauten: {@drawn_numbers.sort}, {@drawn_stars.sort}"; | |
my @matching_numbers = @numbers.grep(any(@drawn_numbers)); | |
my @matching_stars = @stars.grep(any(@drawn_stars)); | |
my $matching_number_cnt = @matching_numbers.elems; | |
my $matching_star_cnt = @matching_stars.elems; | |
my $matching_rank = %rank_for{$matching_number_cnt}{$matching_star_cnt}; | |
say "$matching_number_cnt Nummer(n) und $matching_star_cnt Stern(e) stimmen überein: {@matching_numbers}, {@matching_stars}"; | |
say $matching_rank | |
?? "Sie haben den Rang $matching_rank erreicht" | |
!! 'Sie haben leider keinen Rang erreicht'; | |
until ($input = prompt('Wollen sie noch einmal spielen? j/n: ')) ~~ any( "j", "n" ) {} | |
$play_again = $input eq 'j'; | |
} while $play_again; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment