|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- # Boom
-
- **Problem:**
- Return the numbers 0-n, but replace every number with a '3' as one of the digits with "Boom"
-
- I did this in the type system because I wanted to piss off my flatmate, who gave me this to try out, but also because I hate myself.
-
- I cheated a little at the end, because I cbf converting my representation to standard Church Encoding, so everything is a list of digits instead of a number.
-
- ## Running
-
- start up `ghci` and type:
-
- ```
- :t solution (nil :: X)
- ```
-
- where X is a church encoding using S as the successor function, and Z as the atom.
-
- ## Example
-
- ```
- :t solution (nil :: (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S Z))))))))))))))))))))))))))
- ```
-
- will return (formatted to save your eyes):
-
- ```
- solution (nil :: (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S Z))))))))))))))))))))))))))
- :: Cons
- (Cons Z Nil)
- (Cons
- (Cons (S Z) Nil)
- (Cons
- (Cons (S (S Z)) Nil)
- (Cons
- Boom
- (Cons
- (Cons (S (S (S (S Z)))) Nil)
- (Cons
- (Cons (S (S (S (S (S Z))))) Nil)
- (Cons
- (Cons (S (S (S (S (S (S Z)))))) Nil)
- (Cons
- (Cons (S (S (S (S (S (S (S Z))))))) Nil)
- (Cons
- (Cons (S (S (S (S (S (S (S (S Z)))))))) Nil)
- (Cons
- (Cons (S (S (S (S (S (S (S (S (S Z))))))))) Nil)
- (Cons
- (Cons (S Z)
- (Cons Z Nil))
- (Cons
- (Cons (S Z)
- (Cons (S Z) Nil))
- (Cons
- (Cons (S Z)
- (Cons (S (S Z)) Nil))
- (Cons
- Boom
- (Cons
- (Cons (S Z)
- (Cons (S (S (S (S Z)))) Nil))
- (Cons
- (Cons (S Z)
- (Cons (S (S (S (S (S Z))))) Nil))
- (Cons
- (Cons (S Z)
- (Cons (S (S (S (S (S (S Z)))))) Nil))
- (Cons
- (Cons (S Z)
- (Cons (S (S (S (S (S (S (S Z))))))) Nil))
- (Cons
- (Cons (S Z)
- (Cons (S (S (S (S (S (S (S (S Z)))))))) Nil))
- (Cons
- (Cons (S Z)
- (Cons (S (S (S (S (S (S (S (S (S Z))))))))) Nil))
- (Cons
- (Cons (S (S Z))
- (Cons Z Nil))
- (Cons
- (Cons (S (S Z))
- (Cons (S Z) Nil))
- (Cons
- (Cons (S (S Z))
- (Cons (S (S Z)) Nil))
- (Cons
- Boom
- (Cons
- (Cons (S (S Z))
- (Cons (S (S (S (S Z)))) Nil))
- (Cons
- (Cons (S (S Z))
- (Cons (S (S (S (S (S Z))))) Nil))
- Nil)))))))))))))))))))))))))
- ```
|