main input = print eol (fac (parse input)) fac2 = yy (\ self n acc -> ifLtEq n n1 acc (self (pred n) (times n acc)) ) fac n = fac2 n n1 eol = cons n10 endOfOutput chr d = plus d n48 pr2 = yy (\ self end cns n -> ifLt n n10 (cns (chr n) end) (cns (chr (mod n n10)) (self end cns (div n n10)))) print end n = append (reverse (pr2 nil cons n)) end ord d = minus d n48 parse n = parse2 n n0 parse2 = yy (\ self input acc -> ifGtEq (car input) n57 acc (ifLt (car input) n48 acc (self (cdr input) (plus (times n10 acc) (ord (car input)))) ) ) reverse l = rev2 l nil rev2 = yy (\ self l a -> if3 (isNull l) a (self (cdr l) (cons (car l) a)) ) append = yy (\ self a b -> if3 (isNull a) b (cons (car a) (self (cdr a) b)) ) true = \ x y -> x false = \ x y -> y if3 p x y = p x y cons x y = \ f -> f x y car lst = lst true cdr lst = lst false nil = \ f -> true isNull lst = lst (\ x y -> false) nth n lst = car ((n cdr) lst) kk x y = x eq a b = ( nth b ((a (cons false)) (cons true (listOf false))) ) ifEq m n x y = if3 (eq m n) x y ifLtEq m n x y = (m pow (kk x)) (n pow (kk y)) ifGt m n x y = ifLtEq m n y x ifGtEq m n x y = ifLtEq n m x y ifLt m n x y = ifLtEq n m y x endOfOutput = \f -> n256 listOf elt = yy (cons elt) yy f = (\ x -> x x) (\ self -> f (self self) ) succ a = \ f x -> (f ((a f) x)) plus a = a succ times a b = \ f -> a (b f) pow a b = b a pred n = \ f x -> n (\ g h -> h (g f)) (\ u -> x) (\ u -> u) minus big small = (small pred) big mod = yy (\self big small -> ifGt big small (self (minus big small) small) (ifEq big small n0 big) ) div big small = div2 big small n0 div2 = yy (\self dividend divisor acc -> ifGtEq dividend divisor (self (minus dividend divisor) divisor (succ acc)) acc) n0 = \ f x -> x n1 = \ f -> f n2 = succ n1 n3 = succ n2 n4 = (\ x -> (x x)) n2 n5 = succ n4 n10 = times n2 n5 n16 = (\ x -> x x x) n2 n27 = (\x -> x x) n3 n28 = succ n27 n48 = times n3 n16 n56 = times n2 n28 n57 = succ n56 n256 = (\ x -> (x x)) n4