]> gitweb.factorcode.org Git - factor.git/commitdiff
Speed up map product in poker vocab
authorAaron Schaefer <aaron@elasticdog.com>
Sun, 5 Apr 2009 19:32:36 +0000 (15:32 -0400)
committerAaron Schaefer <aaron@elasticdog.com>
Sun, 5 Apr 2009 19:32:36 +0000 (15:32 -0400)
extra/poker/poker.factor

index c903bcfcb3bc80b8d08a28708d7e6bf3719bd9b4..172bb49506be2f221821338c8052057396438ba0 100644 (file)
@@ -112,15 +112,17 @@ CONSTANT: VALUE_STR { "" "Straight Flush" "Four of a Kind" "Full House" "Flush"
 : rank-bits ( cards -- q )
     0 [ bitor ] reduce -16 shift ;
 
-! Needs MEMO: to prevent unique5 lookup twice?
 : lookup ( cards table -- value )
     [ rank-bits ] dip nth ;
 
 : unique5? ( cards -- ? )
     unique5-table lookup 0 > ;
 
+: map-product ( seq quot -- n )
+    [ 1 ] 2dip [ dip * ] curry [ swap ] prepose each ; inline
+
 : prime-bits ( cards -- q )
-    [ HEX: FF bitand ] map product ;
+    [ HEX: FF bitand ] map-product ;
 
 : hand-value ( cards -- value )
     {