The numbers in the table below are the result of executing an algorithm that has one parameter N, a non-negative integer, and produces sequences of integers as outputs. For values of N from 0 to 5, the algorithm produces the following sequences of numbers as outputs.
1 Answer
$\begingroup$
$\endgroup$
3
Here is one possible algorithm:
- If $N = 0$, output the empty string.
- If $N = 1$, output "0 1".
- If $N = 2$, output "0 2 2 3".
- If $N = 3$, output "0 2 4 3 4 5".
- If $N = 4$, output "0 2 4 6 4 5 6 7".
- If $N = 5$, output "0 2 4 6 8 5 6 7 8 9".
- Otherwise, output the empty string.
Now, this is probably not the answer they were expecting, but it's perfectly valid.
(The answer they expected was: output the first $N$ even integers starting with zero, and then the first $N$ integers starting with $N$.)
-
$\begingroup$ answer of the sequence $\endgroup$Saad Mohamed– Saad Mohamed2019-10-04 13:57:29 +00:00Commented Oct 4, 2019 at 13:57
-
$\begingroup$ Trick question $\Rightarrow$ trick answer! $\endgroup$HEKTO– HEKTO2019-10-04 13:59:37 +00:00Commented Oct 4, 2019 at 13:59
-
2$\begingroup$ I was about to say the same thing! These kind of "problems" are really annoying. There is literally a countable infinity of algorithms that produce that same output. Why should one be preferred (notice that it says "determine the algorithm that was used [...]"? $\endgroup$Steven– Steven2019-10-04 14:21:02 +00:00Commented Oct 4, 2019 at 14:21
