45
2
Background
When I was in elementary school, we used to play a game in math class that goes as follows.
All kids sit in a big circle and take turns counting, starting from 1.
However, the following numbers must be skipped while counting:
- Numbers that are multiples of 3.
- Numbers that have a 3 in its decimal representation.
The first 15 numbers the kids should say are
1 2 4 5 7 8 10 11 14 16 17 19 20 22 25
Whenever somebody gets a number wrong – says a number that isn't in the sequence or skips a number that is – he's removed from the circle. This goes on until there's only one kid left.
Task
You're bad at this game, so you decide to cheat. Write a program or a function that, given a number of the sequence, calculates the next number of the sequence.
You don't have to handle numbers that cannot be represented using your language's native numeric type, provided that your program works correctly up to input 251 and that your algorithm works for arbitrarily large inputs.
Input and output can use any convenient base.
Since you have to conceal your code, it must be as short as possible. In fact, this is code-golf, so the shortest code in bytes wins.
Test cases
1 -> 2
2 -> 4
11 -> 14
22 -> 25
29 -> 40
251 -> 254
5I feel like we had a challenge like this... – Conor O'Brien – 2016-11-03T02:06:38.017
Goddangit the fricking rationale. – Mama Fun Roll – 2016-11-03T03:23:40.457
5It was always
7
that was skipped when I played it, but you'd say something else, instead, rather than going to the next number in line. – mbomb007 – 2016-11-03T13:51:10.5401@mbomb007 Different countries, different games. :) – Dennis – 2016-11-03T14:04:50.460
Related – mbomb007 – 2016-11-03T14:08:45.110
12@mbomb007: When I played it, you would not be removed from the circle. Instead, you would drink. But that wasn't in the elementary school. Anyway, getting over 80 was near impossible, especially after the first hour. – tomasz – 2016-11-03T21:49:55.207
@tomasz Seems like proof that drinking is bad for your intelligence. – mbomb007 – 2016-11-04T14:09:34.043
10
@mbomb007 Depends on the blood alcohol concentration.
– Dennis – 2016-11-04T14:16:13.1374@mbomb007: That would depend on the proof of whatever you are drinking. – tomasz – 2016-11-04T14:16:49.610
Related. I am not aware of the existence of this question when I posted that. – Weijun Zhou – 2018-03-02T08:54:49.083
can I begin in 1->1? – sergiol – 2018-12-13T21:26:56.887
@sergiol The input is the previous number, not an index. – Dennis – 2018-12-13T21:37:32.680
Counting without 3… I feel like it's favorite Valve's game. – val says Reinstate Monica – 2019-04-12T20:34:15.477