Cookpad Code Puzzle 2022
Goal
You can run the Ruby code on a modern browser like Google Chrome. Try to press "Run Ruby" button.
Observe the behavior of method
func
1
and define a method
answer
1
that performs the same behavior as
func
1
.
Code
# You can call `func1` p func1(0) #=> 1 p func1(1) #=> 2 p func1(2) #=> 3 # Can you tell how `func1` is defined? # Hint: def func1(n) = n + ??? # Define `answer1` that works like `func1` def answer1(n) n end
Problem select:
func1
Reset
Run Ruby (or press Ctrl-Enter)
Stop
Loading ruby.wasm...
(Please try reloading if it takes too long)
Output