16
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!
1Hmm, is test case
278
correct? I get the correct result for each of them, but278
becomes86
instead of5
. :S – Kevin Cruijssen – 2017-08-23T09:17:20.3371@KevinCruijssen You're right,
278
is supposed to be86
.279
becomes5
. Fixed! – Arfie – 2017-08-23T09:19:38.6172Related but quite different. – Arnauld – 2017-08-23T09:37:35.427
1I would swear this is a dupe but can't seem to find any. – Erik the Outgolfer – 2017-08-23T10:52:23.073
1@EriktheOutgolfer Actually, I'm sure I've seen this before as well -- not just the one I already mentioned -- but couldn't find it either ... – Arnauld – 2017-08-23T11:44:48.247
@Arnauld Maybe it was deleted or something then. I remember it having something like
1, 2, 3, 4, 5, 6, *1*, 8, 9, ..., 34, ***1***, 36, ...
(where stars are what it looked like in markdown) – Erik the Outgolfer – 2017-08-23T11:46:06.1501
@EriktheOutgolfer Ah! this one, I think (using Google rather than the internal search).
– Arnauld – 2017-08-23T11:55:48.2103@Arnauld Yep that's an exact dupe...or not? That one asks you to print indefinitely, this one asks you for a specific item...it's somewhat like the "count up forever" question vs. my "count up folks!" question. Very different approaches. – Erik the Outgolfer – 2017-08-23T11:56:27.160
5I think it's similar enough to be a duplicate. We don't need both a "print at least
n
terms" and a "print then
th term" of every sequence challenge. – mbomb007 – 2017-08-23T13:33:29.913