Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 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(
|
||||
'^ (?&exp) \z
|
||||
(?(DEFINE)
|
||||
(?<exp> ( (?&term) (?&op) (?&term) )+ )
|
||||
(?<term> \( (?&exp) \) | [' + digits.join + '])
|
||||
(?<op> [\-+*/] )
|
||||
)', 'x'
|
||||
)
|
||||
|
||||
say "Here are your digits: #{digits.join(' ')}"
|
||||
|
||||
loop {
|
||||
var input = read("Expression: ", String)
|
||||
|
||||
var expr = input
|
||||
expr -= /\s+/g # remove all whitespace
|
||||
|
||||
if (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