2 ms·
Should I be worried that I couldnt come up with a proper solution for this. How do you get better at solving such questions ?
by thewarrior 13y ago
Should I be worried that I couldnt come up with a proper solution for this. How do you get better at solving such questions ?
- tomp 13y ago1) Write down all you know. Seeing `f(f(n)) == n` is frightening and tells your mind nothing, it just blocks it. If you start with a simple example, say `f(f(1)) == 1`, you then say `f(1) == y` for some `y`, and then you can "generalize": `f(x) == y`, `f(y) == -x`. 2) Simplify and limit the problem: instead of `f : int32 -> int32`, have `f : {-2, -1, 0, 1, 2} -> [-2, 2]`. Then, you would probably think of the sequence `f : 1 -> y -> -1 -> -y`, from which you see that either `y == 2` or `y == -2`. Or, you would figure out another sequence, say `f : 1 -> 0.5 -> -1 -> -0.5` or something similar. So: write down what you know, and try simple/limited examples first.