This challenge is based on a drinking game. I advise against alcohol consumption while programming.
In this game, the players count up in turns: the first player says 1
, the second says 2
and so on. Here's the twist however: each number that is divisible by 7 or has a 7 in its digits (in base 10) is replaced by another counter. This means 7
is replaced by 1
, 14
is replaced by 2
, 17
is replaced by 3
and so on. For this "sub-sequence", the same rules apply! 35
would be replaced by 7
, which in turn is replaced by 1
. This process repeats until the number is "valid".
Here's a visualization of the first 100 numbers in the sequence:
n = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
gets replaced by:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
gets replaced by:
1 2 3 4 5 6
final sequence:
1 2 3 4 5 6 1 8 9 10 11 12 13 2 15 16 3 18 19 20 4 22 23 24 25 26 5 6 29 30 31 32 33 34 1 36 8 38 39 40 41 9 43 44 45 46 10 48 11 50 51 52 53 54 55 12 13 58 59 60 61 62 2 64 65 66 15 68 69 16 3 18 19 20 4 22 23 24 25 80 81 82 83 26 85 86 5 88 89 90 6 92 93 94 95 96 29 30 99 100
In the final sequence, no number has a seven in its digits or is divisible by seven.
Input description
- An integer
n
(1 <= n <= 7777
or0 <= n <= 7776
)
You may choose whether you use a 0-indexed or 1-indexed input.
Output description
- The
n
th number in the sequence
Examples
The examples are 1-indexed. For 0-indexed, subtract one from n
.
n -> f(n)
1 1
5 5
7 1
35 1
77 23
119 1
278 86
2254 822
2255 2255
7777 3403
Scoring
This is code-golf, so shortest answer in bytes wins!
278
correct? I get the correct result for each of them, but278
becomes86
instead of5
. :S \$\endgroup\$278
is supposed to be86
.279
becomes5
. Fixed! \$\endgroup\$n
terms" and a "print then
th term" of every sequence challenge. \$\endgroup\$