June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
18
Task/24-game-Solve/Factor/24-game-solve.factor
Normal file
18
Task/24-game-Solve/Factor/24-game-solve.factor
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
USING: continuations grouping io kernel math math.combinatorics
|
||||
prettyprint quotations random sequences sequences.deep ;
|
||||
IN: rosetta-code.24-game
|
||||
|
||||
: 4digits ( -- seq ) 4 9 random-integers [ 1 + ] map ;
|
||||
|
||||
: expressions ( digits -- exprs )
|
||||
all-permutations [ [ + - * / ] 3 selections
|
||||
[ append ] with map ] map flatten 7 group ;
|
||||
|
||||
: 24= ( exprs -- )
|
||||
>quotation dup call( -- x ) 24 = [ . ] [ drop ] if ;
|
||||
|
||||
: 24-game ( -- )
|
||||
4digits dup "The numbers: " write . "The solutions: "
|
||||
print expressions [ [ 24= ] [ 2drop ] recover ] each ;
|
||||
|
||||
24-game
|
||||
Loading…
Add table
Add a link
Reference in a new issue