1 ! Copyright (C) 2019-2020 KUSUMOTO Norio.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs formatting io kernel lists logic math sequences ;
4 IN: logic.examples.money
6 LOGIC-PREDS: sumo sum1o digitsumo delo donaldo moneyo ;
7 LOGIC-VARS: S E N D M O R Y A L G B T
9 Digits Digs Digs1 Digs2 Digs3 ;
12 { sum1o N1 N2 N 0 0 L{ 0 1 2 3 4 5 6 7 8 9 } __ }
15 { sum1o L{ } L{ } L{ } 0 0 Digits Digits } fact
16 { sum1o L{ D1 . N1 } L{ D2 . N2 } L{ D . N } C1 C Digs1 Digs } {
17 { sum1o N1 N2 N C1 C2 Digs1 Digs2 }
18 { digitsumo D1 D2 C2 D C Digs2 Digs }
21 { digitsumo D1 D2 C1 D C Digs1 Digs } {
22 { delo D1 Digs1 Digs2 }
23 { delo D2 Digs2 Digs3 }
25 [ [ [ D1 of ] [ D2 of ] [ C1 of ] tri + + ] S is ]
26 [ [ S of 10 mod ] D is ]
27 [ [ S of 10 /i ] C is ]
30 { delo A L L } { { nonvaro A } !! } rule
31 { delo A L{ A . L } L } fact
32 { delo A L{ B . L } L{ B . L1 } } { delo A L L1 } rule
46 :: S-and-M-can't-be-zero ( seq -- seq' )
48 1 hash N1 of lnth 0 = not
49 1 hash N2 of lnth 0 = not and
52 :: print-puzzle ( hash-array -- )
55 " " printf hash N1 of [ "%d " printf ] leach nl
56 "+ " printf hash N2 of [ "%d " printf ] leach nl
57 "----------------" printf nl
58 " " printf hash N of [ "%d " printf ] leach nl nl