diff --git a/src/game/problems/index.js b/src/game/problems/index.js index e0a63ac..da902f0 100644 --- a/src/game/problems/index.js +++ b/src/game/problems/index.js @@ -602,6 +602,123 @@ export default [ ) ) }, + { + title: "Mixing Booleans and Numbers", + prompt: ( +
lol define the ISZERO function by composing const false with itself n times, starting at true.
+Answer is: λf.f(λt.FALSE)TRUE
+lol we can define pairs
+What's a pair? a way to put 2 things in and a way to pull one of 2 things out?
+It's gonna be a function that takes 2 arguments and puts it like
+We define it PAIR := λabf.f ab
+We can use this function to define pairs, as such!
+We can see that executing + PAIR x y + will result in + λf.fxy +
+Define the pair (FALSE, TRUE), and assign it to MYPAIR
+(The astute of you will notice that this will result in something that's identical to the NOT function we wrote earlier!)
+Let's see if we can define the First and Second functions, FST and SND, e.g. FST (PAIR x y) == x and FST (PAIR x y) == y
+Like all other 'values' in the Lambda Calculus, we lean on the structure of the data type when we want to do operations. As we noted earlier, this is very similar to the NOT function we made earlier, so see if you can use that fact to help you towards a solution here.
+Answer: FST := λx.x TRUE
+Answer: SND := λx.x FALSE
+Now we're going to go down a slightly unexpected path -- We'll start by defining a pretty tricky function
+Make a function that takes a pair of numbers, moves the right number to the left slot, and moves the left number to the right slot and adds one.
+So your transition function can be summarized as TRANSITION: (a, b) -> (b, a + 1). Don't worry if this takes a long time.
+Here are some sample pairs to check your understanding:
+Now try running it on the pair (0, 0)
+If you really want, you can just write the resulting pair yourself. I don't mind.
+This isn't going to make much sense, but try to compose that function N times, starting at (0, 0)
+We can imagine the sequence after n iterations, Define the function TRANSFORM_N that transforms (0, 0) n times.
+A sample sequence is shown below.
+Now, the magic: Take the first item of that resulting pair.
+By the way we've constructed this transition function, it turns out that n yields n - 1! This is your predecessor function.
+Assign this function to PRED
+Sweetness. We can compose this together n times to get subtraction, in the exact same way we did addition before.
+This should be easy enough. Write SUB, the subtraction function
+