0
$\begingroup$

enter image description here

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.

$\endgroup$
  • 2
    $\begingroup$ I'm voting to close this question as off-topic because it is a puzzle rather than a technical question. $\endgroup$ – Yuval Filmus Oct 5 '19 at 22:56
7
$\begingroup$

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$.)

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ answer of the sequence $\endgroup$ – Saad Mohamed Oct 4 '19 at 13:57
  • $\begingroup$ Trick question $\Rightarrow$ trick answer! $\endgroup$ – HEKTO Oct 4 '19 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 Oct 4 '19 at 14:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.