3 slowSum :: [Integer] -> <Proc> Integer
4 slowSum list = getRef answer
11 -El ?x, -El ?y => El (?x + ?y)
14 main = slowSum [1,6,9]
20 slowGcd :: [Integer] -> <Proc> Integer
21 slowGcd list = getRef answer
25 constraint Gcd Integer
29 -Gcd ?m, Gcd ?n, ?n <= ?m => Gcd (?m `mod` ?n)
30 Gcd ?answer => answer := ?answer
32 main = slowGcd [12,20]
38 isReachable :: [(Integer,Integer)] -> Integer -> Integer -> <Proc> Boolean
39 isReachable edges a b = getRef answer
43 constraint Edge Integer Integer
44 constraint Reachable Integer
46 (?x,?y) <- edges => Edge ?x ?y
48 Reachable ?x, Edge ?x ?y => Reachable ?y
49 Reachable b => answer := True
51 graph :: [(Integer, Integer)]
52 graph = [(0,1), (1,2), (2,3), (4,5)]
54 main = (isReachable graph 0 3, isReachable graph 0 5)
58 import "StandardLibrary"
60 primes1 limit = MList.freeze answer
62 answer = MList.create ()
65 constraint Prime Integer
66 constraint PrimeCandidate Integer
68 True => PrimeCandidate 3
69 -PrimeCandidate ?x, ?x > limit => True
70 -PrimeCandidate ?x, Prime ?y, ?x `mod` ?y = 0 => PrimeCandidate (?x + 2)
71 -PrimeCandidate ?x => MList.add answer ?x, Prime ?x, PrimeCandidate (?x + 2)
75 [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
77 import "StandardLibrary"
79 powersOfTwo n = sort (MList.freeze answer)
81 answer = MList.create ()
86 -N ?x, -N ?x => N (2*?x)
87 N ?x => MList.add answer ?x
93 import "StandardLibrary"
95 main = MList.freeze answer
97 answer = MList.create ()
98 add = MList.add answer
115 [A1, A2, B1, B2, C1, C2]
117 import "StandardLibrary"
119 graph = [("1","2"), ("2","3"), ("3","4"), ("3","5"), ("1","4"), ("5","5")]
121 main = sort (MList.freeze answer)
123 answer = MList.create ()
126 constraint Edge String String
127 constraint Degree String Integer
130 (?x, ?y) <- graph => Edge ?x ?y
132 Init, Edge ?x ?y => Degree ?x 1, Degree ?y 1
133 Init, -Degree ?x ?a, -Degree ?x ?b => Degree ?x (?a + ?b)
136 -Degree ?x 0 => print "Remove node \(?x)"
137 -Degree ?x ?a, -Edge ?x ?x => Degree ?x (?a - 2), print "Remove loop (\(?x),\(?x))"
138 -Degree ?x ?a, -Edge ?x ?y, -Degree ?y ?b, (?a==1 || ?b==1) => Degree ?x (?a - 1), Degree ?y (?b - 1), print "Remove dangling edge (\(?x),\(?y))"
139 -Degree ?y 2, -Edge ?x ?y, -Edge ?y ?z => Edge ?x ?z, print "Simplify path (\(?x),\(?y),\(?z))"
141 Edge ?x ?y => MList.add answer (?x, ?y)
145 import "StandardLibrary"
147 uniq :: [a] -> <Proc> [a]
148 uniq l = MList.freeze answer
150 answer = MList.create ()
154 -El ?x, El ?x => True
155 El ?x => MList.add answer ?x
157 main = sort $ uniq [1,1,2,2,3]