]> gitweb.factorcode.org Git - factor.git/commitdiff
24-game: cleanup.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 19 Apr 2016 03:48:20 +0000 (20:48 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 19 Apr 2016 03:48:20 +0000 (20:48 -0700)
extra/24-game/24-game.factor

index 94bc1ebd6a568890171d71dc80b28553309aa70e..f0d43bf66eb8f003687e1817342c7290b5d087ea 100644 (file)
@@ -1,9 +1,8 @@
 ! Copyright © 2008 Reginald Keith Ford II
 ! 24, the Factor game!
-
-USING: accessors backtrack continuations io kernel math
-math.parser prettyprint quotations random sequences shuffle ;
-
+USING: accessors backtrack combinators continuations io kernel
+math math.parser prettyprint quotations random sequences shuffle
+;
 IN: 24-game
 
 : nop ( -- ) ;
@@ -54,20 +53,22 @@ CONSTANT: (operators) { + - * / rot swap q }
     bi ;
 
 : end-game ( array -- )
-    dup { 24 } =
-    [ drop "You WON!" ]
-    [ first number>string " is not 24... You lose." append ]
-    if print ;
-
-: (24-game) ( array -- )
-    dup length 1 =
-    [ end-game ] [
-        dup last "quit" =
-        [ drop "you're a quitter" print ]
-        [ try-operator (24-game) ]
-        if
-    ] if ;
-
-: 24-game ( -- ) make-24 (24-game) ;
+    dup { 24 } = [
+        drop "You WON!"
+    ] [
+        first number>string " is not 24... You lose." append
+    ] if print ;
+
+: quit-game ( array -- )
+    drop "you're a quitter" print ;
+
+: play-24 ( array -- )
+    {
+        { [ dup length 1 = ] [ end-game ] }
+        { [ dup last "quit" = ] [ quit-game ] }
+        [ try-operator play-24 ]
+    } cond ;
+
+: 24-game ( -- ) make-24 play-24 ;
 
 MAIN: 24-game