-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsimpleplus3.tel
More file actions
42 lines (28 loc) · 1.12 KB
/
simpleplus3.tel
File metadata and controls
42 lines (28 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
id = \x -> x
and2 = \a b -> if a then (if b then 1 else 0) else 0
not2 = \x -> if x then 0 else 1
succ2 = \x -> (x,0)
makeRecur = \n t r b -> n (\c i -> if t i then r c i else b i) b
d2c2 = \n f b -> { id
, \recur i -> f (recur (left i))
, \i -> b
} n
d2c3 = \n f b -> fakeRecur $15 id (\recur i -> f (recur (left i))) (\i -> b)
c2d2 = \c -> c succ2 0
assert2 = \t s -> if not t then (1, s) else 0
times2 = \m n f -> m (n f)
-- validDigit = \x -> and2 ($47 left x) (not2 ($57 left x)) -- works
validDigit = \x -> not2 ($57 left x) -- does not work??
-- validInput = \x -> assert2 (and2 (validDigit (left x))
-- (not2 ($3 right x)))
-- "!"
validInput = \x -> assert2 (validDigit (left x)) "!"
toI = \x -> $48 left x
doAdd = \x -> c2d2 (times2 (d2c2 (toI x)) $9)
main = \input -> let inString : validInput = left input
x = left inString
r = doAdd x
dr = $49 succ2 r
in if not input
then ("?", 1)
else (dr, 0)