# Participant number

A math Olympiad will be held, and participants are being registered. The highest number of participants is 100. Each participant is given an ID number. It is given in a sequence like $$\100, 97, 94, 91, 88, ...., 1\$$, and when the first sequence is over, then $$\99, 96, 93, 90, 87, ...., 3\$$ sequence and so on.

Let's assume one of the participant's ID number is $$\k\$$ and he/she is the $$\n^{th}\$$ participant. Given the value of $$\k\$$, return the value of $$\n\$$.

Test Cases

59 -> 81
89 -> 71
16 -> 29
26 -> 92
63 -> 47
45 -> 53
91 -> 4
18 -> 62
19 -> 28


There will be no leading zero in input. Standard loopholes apply, shortest code wins. In output there can be trailing whitespace.

• Can you specify how this sequence works? Also this would work better under standard sequence rules in my opinion. – Redwolf Programs Apr 21 at 2:32
• I doubt it. It's very easy anyway. – Redwolf Programs Apr 21 at 2:36
• These test cases are awful. They are extremely inconvenient for testing and there is a duplicate. Did you generate them randomly? – Redwolf Programs Apr 21 at 2:45
• Just so we're absolutely clear here, from what I can infer the third sequence id the final one and goes 98,95,...,2? Because if not then you need to specify it in the description. – ophact Apr 21 at 5:18
• 2 -> 100 should definitely be a test case (since it catches an edge-case if using a mod 100). – Jonathan Allan Apr 21 at 16:27

# Python 2, 23 bytes

lambda n:1-199*~n/3%~99


Try it online!

I kind-of just tried stuff until I got something that worked.

# Python 2, 27 bytes

Some magic formula after a bit of trial and error.

lambda n:~-~n%3*33+34-~-n/3


Try it online!

# Husk, 11 9 bytes

€ΣTC3ṫ100


-2 bytes, borrowing Unrelated String's idea.

## Explanation

€ΣTC3ṫ100
ṫ100 [100..1]
C3     slices of 3
T       transpose
Σ        join
€         index of input


# Jelly, 9 bytes

ȷ2RUs3ZFi


Try it online!

   U         Reverse
R          the inclusive range from 1 to
ȷ2           100.
s3       Split it into slices of length 3,
Z      zip the slices,
F     flatten the columns,
i    and find the index of the input in the resulting list.

• Right, idk how I didn't think of using zip. I was thinking it'd be convenient if there were a way to take each block of three and then go through them column-wise... – hyper-neutrino Apr 21 at 3:25

# JavaScript (V8), 33 20 bytes

Thanks to @tsh for -13

n=>101+~n%3*33-n/3|0


Try it online!

Old:

n=>(n=100-n)%3*33+n/3+1+!!(n%3)|0


Try it online!

I don't know why this works. Don't question it.

• Do you need |0 at the end? – radrow Apr 21 at 6:06
• After some math simplify: Maybe n=>101+~n%3*33-n/3|0 – tsh Apr 21 at 9:44

# J, 28 27 26 24 bytes

(_,;(</.~3|])i._100)i.<:


Try it online!

-2 bytes thanks to Bubbler

• 24 bytes using parenthesized noun expression. – Bubbler Apr 21 at 4:08

# Desmos, 3032 31 bytes

ceil(mod(67.1-101\frac n3,100))


Try it here!

+2 bytes to account for edge case at 2
-1 byte thanks to Jonathan Allan!

• @JonathanAllan well, darn. I've always thought there should be an equivalent to $\mod n$ where multiples of $n$ go to $n$ instead of $0$, but no such operation exists... this workaround will have to do. – hakr14 Apr 21 at 17:56
• @JonathanAllan brilliant, thanks! – hakr14 Apr 21 at 18:36

# Pari/GP, 23 bytes

p(n)=-n\3+(1-n)%3*33+35


Try it online!

2 more bytes saved thanks to Dominic van Essen

• Nice! Looks like you can swap -n+1 for n-1 to save 1 byte... – Dominic van Essen Apr 21 at 16:20
• No, I want a function f: f=(0,1,2) for n=(100,99,98). To do that I need to reverse the results given by n%3, making the results (2,0,1) instead of (1,0,2) and cycle them to the right, giving (0,1,2). But I clearly should have done (1-n) instead of (-n+1), is it too late to fix it? – Joe Slater Apr 22 at 2:15
• You're right: that was a typo by me. Of course not too late to fix it - many of us 'fix' our answers continuously (look at all the crossed-out previous byte scores)! Just click 'edit' below the post. If you like (there's no requirement), you can leave the old score of 26 crossed out by surrounding it with <s> & </s>... – Dominic van Essen Apr 22 at 5:07
• Done, thanks for the tip! – Joe Slater Apr 22 at 6:09
• Also: if you rearrange by pre-dividing 99 and 105 by 3, you'll save 2 more bytes (and end-up with the same formula that I used, but arriving by a different route!)... – Dominic van Essen Apr 22 at 7:00

# Jelly, 12 bytes

101ḶUẋ3m3ḟ0i


Try it online!

# Python 3.8 (pre-release), 34 bytes

-8 bytes thanks to ovs!

lambda a:101-round(-~a%3*33.3+a/3)


Try it online!

• [1,2,0][a%3] can be golfed to -~a%3* and int(...+.5) is the same as round(...). 34 bytes – ovs Apr 21 at 6:46

# Vyxal, 11 10 bytes

Thanks to @Razetime for -1 byte by writing 199 as ⁺b.

ꜝ⁺b*3ḭ₁N%⌐


Try it Online!

Vyxal port of @xnor's Python answer, with a bit of extra golfing.

Explanation:

            # Note: 'X' denotes current value.

# Implicit input
ꜝ           # ( X + 1 ) * -1
⁺b*        # X * 199
3ḭ      # X // 3
₁N%   # X % -100
⌐  # 1 - X
# Implicit output
$$$$


# Charcoal, 18 bytes

Ｉ⊕÷﹪⁻²⁰¹×¹⁰¹Ｎ³⁰⁰¦³


Try it online! Link is to verbose version of code. Explanation: Implements the formula n=1+(201-101*k)%300/3, which I found through trial and error.

# Japt, 13 bytes

Lõ Ôó3 c aU Ä
Lõ            // Create the range [1..100],
Ô          // reverse it and
ó3        // group by every third item.
c      // Flatten the result, then
aU Ä // return the index of input plus one.


Try it here.

# R, 30 bytes

k=scan();35+-k%/%3+33*(1-k)%%3


Try it online!

There are already 12 other answers in various languages before I managed to post this, and - amazingly for what seems such a simple task - they mostly seem to use different formulas/strategies to each other, and all appear to be different to this one.

I suspect this means that if I go-through all the other approaches, I'll find that at least some of them will turn-out to be golfier than this one, though...

# Arn-IF, 12 bytes

Found a few bugs while writing this, lol. This is 0-indexed (e.g. 59 -> 80), I'm not sure if that's okay so I can change the answer if it isn't (somebody asked in the comments but there was no response).

&»¨)¢►†3K1v&


# Explained

Unpacked: e2.~::%3-1& .@

I see some answers explain like this:

  e2.~    Descending range from 100 to 1
::%3-1  Sort in chunks of 3
& .@    Bind the transpose operator to the output


And others like this:

    e2   1 * 10 ^ 2 = 100
.~     Descending range
::       Sort adjacently while the right is truthy
_    The currently value
%      Modulo
3    Three
-        Minus
1      One
&        Bind
.@     The transpose operation


So I might as well include both. Either way, there is an implicit :_ and :i surrounding the program. The space in & .@ is required because &. is a symbol in the language already. I admit the flags are a bit cheaty, so for anybody curious this would be 15 bytes without the two flags.

# 05AB1E, 11 bytes

тLR3ôζ˜þIk>


Alternatively, a port of @xnor's Python answer (which only works in the legacy version of 05AB1E due to the negative modulo) would be 11 bytes as well:

$±Ƶ$*3÷т(%-


Explanation:

тLR          # Push a list in the range [100,1]
3ô        # Split it into parts of size 3
ζ       # Zip/transpose the list, using a space as filler
˜      # Flatten this list of triplets
þ     # Remove the spaces by only leaving digits
Ik   # Get the (0-based) index of the input in this list
>  # Increase it by 1 to make it a 1-based index
# (after which the result is output implicitly)

$# Push 1 and the input ± # Get the Bitwise-NOT of that: -input-1 Ƶ$*        # Multiply it by 199
3÷      # Integer-divide it by 3
т(%   # Modulo -100
$- # Subtract it from the 1 we pushed at the start # (after which the result is output implicitly)  See this 05AB1E tip of mine (section How to compress large integers?) to understand why Ƶ$ is 199`.