Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
36
Task/24-game/Sidef/24-game.sidef
Normal file
36
Task/24-game/Sidef/24-game.sidef
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
const digits = (1..9 -> pick(4));
|
||||
const grammar = Regex.new(
|
||||
'^ (?&exp) \z
|
||||
(?(DEFINE)
|
||||
(?<exp> ( (?&term) (?&op) (?&term) )+ )
|
||||
(?<term> \( (?&exp) \) | [' + digits.join + '])
|
||||
(?<op> [-+*/] )
|
||||
)', 'x'
|
||||
);
|
||||
|
||||
say "Here are your digits: #{digits.join(' ')}";
|
||||
|
||||
loop {
|
||||
var input = Sys.scanln("Expression: ");
|
||||
|
||||
var expr = input;
|
||||
expr -= /\s+/g; # remove all whitespace
|
||||
|
||||
input == 'q' && (
|
||||
say "Goodbye. Sorry you couldn't win.";
|
||||
break;
|
||||
);
|
||||
|
||||
var given_digits = digits.map{.to_s}.sort.join;
|
||||
var entry_digits = input.scan(/\d/).sort.join;
|
||||
|
||||
if ((given_digits != entry_digits) || (expr !~ grammar)) {
|
||||
say "That's not valid";
|
||||
next;
|
||||
}
|
||||
|
||||
given(var n = eval(input)) {
|
||||
when (24) { say "You win!"; break }
|
||||
default { say "Sorry, your expression is #{n}, not 24" }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue