You have a hidden function. You can't see the code.
All you can do is give it inputs and inspect the outputs and your job is to figure out what it does.
For example:
f("hello") → "ohell"
f("world") → "dworl"
f("codeset") → "tcodese"
This one is pretty easy, but now imagine the pattern isn't so obvious. That's the idea behind a little game we built called Mystery Function:
Every day there's a new hidden function to figure out. You can test at most 6 inputs. Once you think you know the function, you have to predict its output for two new inputs to prove it.
What I like about the idea is that it reverses the normal programming problem. Usually you're given a specification and asked to write the implementation. Here, you're given the behavior and asked to recover the specification.
And pretty quickly, it stops being about throwing random inputs at the function. You start designing experiments.
"What input would distinguish between these two possibilities?"
"What edge case would break my current theory?"
"What haven't I tested yet?"
The loop becomes:
- Test an input.
- Inspect the output.
- Form a hypothesis.
- Try to break your own hypothesis.
- Repeat until you're confident enough to submit.
We shared it on Hacker News and it unexpectedly made the front page. A lot of developers seemed to find this kind of black-box debugging surprisingly addictive.
So I thought DEV might enjoy it too.
Today's function is waiting here:
👉 https://codeset.ai/function
If you solve it, I'm curious how many tests it took you.
Top comments (0)