rxdave / lambdaenigma.com Goto Github PK
View Code? Open in Web Editor NEWλ Enigma
Home Page: http://lambdaenigma.com
License: Apache License 2.0
λ Enigma
Home Page: http://lambdaenigma.com
License: Apache License 2.0
Confused? Don't sweat it. The concept of this game is new to everyone!
Here are some helpful tips.
(parameter list) => body
p => body
This is an introductory puzzle that is meant to help you get started.
This puzzle only has a single piece that you must use in your solution. This piece is a function named d
and its definition is displayed on top of the puzzle:
d = x => x * 2
The function's name, d
, is shown to the left of the equals sign (=). To the right is the piece's function.
x => x * 2
It can be read out loud as, "x goes to x times two".
This function returns double its input. If you pass it 2, then it returns 4. If you pass it 5, then it returns 10.
To use this piece in your solution, you could apply d
to some argument, x
. We'll see how in a moment.
The value to the left, 21, is the input to the lambda expression that you must write to solve this puzzle.
So, let's start by binding the input to a parameter. We'll call it input
, although we can use any letter or combination of letters and numbers (as long as it starts with a letter).
input
Another typical name to use for the input parameter is simply x
.
Before we continue, we'll write the lambda arrow to separate the parameter list from the body of our expression:
input =>
And now we must write the body of our lambda expression. This is the part that returns a value using all of the pieces of the puzzle, which are defined above the puzzle. In this puzzle, we have only one piece: d
.
Before we can use d
, let's see what our lambda expression must return!
The value to the right, 42, is the value that our lambda expression must return in order for our solution to be correct.
So let's take account of what we know:
d
, which doubles any input that it's given.So let's apply d
to input
!
input => d(input)
There's another way to solve this puzzle, but it's somewhat subtle.
Take a look at the definition of d
again. Let's try to infer its data types and thus its signature.
d = x => x * 2
We know that d
returns a number, due to the use of the multiplication operator *
and the literal value 2
. We can also infer that x
must be a number, since it's being multiplied.
Perhaps the definition of d
could be written like this:
d: int -> int
In other words, d
takes an integer and returns an integer.
Now let's examine the signature of the function we must write to solve puzzle #0.
Therefore, the definition is the following:
int -> int
Well, that's identical to the definition of d
!
Therefore, there's a very simple solution to this puzzle:
d
I got to level 10, but I think the "If" implementation is not working. Or it could very well be me.
The editor tells me:
given the definition of If: (p, a, b) => p(a, b)
I don't understand why the second expression gives an argument mismatch ? it should be directly equivalent to the first
Currently it seems the progress is tied to the machine, it would be nice if we can create an account somehow so we can continue on another machine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.