Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
42
Task/24-game/Factor/24-game-1.factor
Normal file
42
Task/24-game/Factor/24-game-1.factor
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
USING:
|
||||
combinators.short-circuit
|
||||
continuations
|
||||
eval
|
||||
formatting
|
||||
fry
|
||||
kernel
|
||||
io
|
||||
math math.ranges
|
||||
prettyprint
|
||||
random
|
||||
sequences
|
||||
sets ;
|
||||
IN: 24game
|
||||
|
||||
: choose4 ( -- seq )
|
||||
4 [ 9 [1,b] random ] replicate ;
|
||||
|
||||
: step ( numbers -- ? )
|
||||
readln
|
||||
[
|
||||
parse-string
|
||||
{
|
||||
! Is only allowed tokens used?
|
||||
[ swap { + - / * } append subset? ]
|
||||
! Digit count in expression should be equal to the given numbers.
|
||||
[ [ number? ] count swap length = ]
|
||||
! Of course it must evaluate to 24
|
||||
[ nip call( -- x ) 24 = ]
|
||||
} 2&&
|
||||
[ f "You got it!" ]
|
||||
[ t "Expression isnt valid, or doesnt evaluate to 24." ]
|
||||
if
|
||||
]
|
||||
[ 3drop f "Could not parse that." ]
|
||||
recover print flush ;
|
||||
|
||||
: main ( -- )
|
||||
choose4
|
||||
[ "Your numbers are %[%s, %], make an expression\n" printf flush ]
|
||||
[ '[ _ step ] loop ]
|
||||
bi ;
|
||||
4
Task/24-game/Factor/24-game-2.factor
Normal file
4
Task/24-game/Factor/24-game-2.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
IN: scratchpad main
|
||||
Your numbers are { 4, 1, 8, 2 }, make an expression
|
||||
8 4 + 2 * 1 /
|
||||
You got it!
|
||||
Loading…
Add table
Add a link
Reference in a new issue