AB猜數字(不行在這沒有互動的終端機上跑)

Run Settings
LanguageRaku
Language Version
Run Command
#!/usr/bin/env perl6 use v6; my Int constant $howManyShouldPick = { repeat { $_ = prompt("要猜幾個數字,也就是說要生成幾個亂數\n") } until $_ ~~ /^ \d+ $/; $_ }.(); my Int constant @randPick = ^10 .roll($howManyShouldPick); my Int @input; my Int $countForHowManyTimes = 0; "猜數字,有 $howManyShouldPick 個數字(每一個範圍是0 .. 9)".say; repeat { repeat { @input = prompt("請輸入 $howManyShouldPick 個數字,不能多不能少\n") .split("",:skip-empty) .grep(/\d/) .map({ .Int }); } until @input.elems == $howManyShouldPick; say qq:to/END/; 你答的次數有 { ++ $countForHowManyTimes } 次 你答對的元素有 { (@input.Bag ∩ @randPick.Bag).values.sum } 個 你答對的順序有 { [+] (@input «==» @randPick) } 個 END } until [&&] (@input «==» @randPick) ; "你答對了,恭喜".say;
Editor Settings
Theme
Key bindings
Full width
Lines