33
\$\begingroup\$

This is an challenge where each answer must take an integer \$N\$ as input and return the 1-indexed ID of the answer which was written by the user whose ID is \$N\$.

You may want to sort by oldest to get the answers in the logical order.

Rules

  1. I will post the first answer.
  2. You are only allowed to post one answer, so that a user ID is linked to one and only one answer ID.
  3. You are only supposed to support user IDs that were used in the previous answers and your own user ID. (So your code may return anything or crash when given an unknown user ID.)
  4. The maximum code size is set to 50 bytes. So the challenge will end when nobody is able to add a new ID without exceeding this size.
  5. You may use any language, no matter which ones were used before. It is recommended to use verbose languages early in the chain, while they still have a chance to compete.
  6. The last valid answer in the chain on January 19, 2022 at 18:00 UTC wins the challenge.

Please include in your post the list of ID pairs, updated with your new entry:

[your_user_ID] -> [your_answer_ID]

Also make sure to include the ID of your answer in the header.

Examples

The first answer is written by user Arnauld (58563):

1. JavaScript (ES6), 4 bytes

_=>1

Try it online!

Updated list:

58563 -> 1

This code returns 1 when given 58563 (my user ID) ... or any other input. That's fine because 1 is the only possible output at this point (see rule #3).

The second answer is written by user JohnDoe (123456) (who actually doesn't exist yet):

2. Python 2, 14 bytes

lambda n:2-n%2

Try it online!

Updated list:

58563 -> 1
123456 -> 2

This code returns 1 when given 58563 or 2 when given 123456.

\$\endgroup\$
2
  • \$\begingroup\$ Sandbox \$\endgroup\$ – Arnauld Jan 19 at 16:18
  • 2
    \$\begingroup\$ @LuisMendo Being the last one I assume. \$\endgroup\$ – Kevin Cruijssen Jan 19 at 17:04

21 Answers 21

13
\$\begingroup\$

7. Julia, 17 bytes

works due to Int64 overflowing to negative numbers

x->(x-8479)^6%5+5

Try it online!

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7

I found those numbers by guessing and brute-forcing :

for i in Iterators.product(-9999:9999,1:20,1:20)
    d = diff(((L.+i[1]) .^ i[3]) .% i[2])
    if all(==(-1), d) || all(==(1),d)
        println(i)
        println(((L.+i[1]) .^ i[3]) .% i[2])
        break
    end
end

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ How did you come up with this? Can you show your approach? \$\endgroup\$ – Anunay Jan 20 at 7:22
8
\$\begingroup\$

2. Ruby, 11 bytes

->x{1+~x%2}

Try it online!

Updated list:

58563 -> 1
80214 -> 2
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Was ->x{2-x%2} too much like the example for you? \$\endgroup\$ – Neil Jan 23 at 1:08
  • \$\begingroup\$ You read my mind. \$\endgroup\$ – Razetime Jan 23 at 3:29
7
\$\begingroup\$

1. JavaScript (ES6), 4 bytes

_=>1

Try it online!

Updated list:

58563 -> 1
\$\endgroup\$
7
\$\begingroup\$

6. Zsh, 26 25 bytes

a=80596
<<<$a[(i)${1[2]}]

Try it online!

Boring.

-1 by @GammaFunction

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
\$\endgroup\$
0
7
\$\begingroup\$

8. J, 46 bytes

Last time this works, here to grab the boring answer!

1+58563 80214 95792 89930 86147 97857 98541&i.

95594 doesn't need to be included as J's index-of-operator i. returns the length of the array in the case the item was not found. But as it is 0-based, the index gets incremented 1+.

Try it online!

Update list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
\$\endgroup\$
3
  • \$\begingroup\$ Since the last two digits are unique, could you just use those? \$\endgroup\$ – user Jan 19 at 19:14
  • 2
    \$\begingroup\$ @user Sure, but then this wouldn't be the last most boring answer! :-) From now on answers will probably have more operations than mine because of the byte limit. \$\endgroup\$ – xash Jan 19 at 19:31
  • \$\begingroup\$ The last last boring answer :) \$\endgroup\$ – user Jan 19 at 22:18
7
\$\begingroup\$

9. Perl 5 -p, 46, 37 bytes

$_=(a74a298635=~/./g)[$_%26%20%12]||1

Try it online!

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9

Explanation:

$_=$_%26%20%12 gives
58563 -> 11
80214 -> 4
95792 -> 8
89930 -> 2
86147 -> 9
97857 -> 7
98541 -> 1
95594 -> 6
70745 -> 5
(a74a298635=~/./g) because shorter than (a,7,4,a,2,9,8,6,3,5)
\$\endgroup\$
1
  • \$\begingroup\$ @MarcMush, golfed, i will try to add an explanation \$\endgroup\$ – Nahuel Fouilleul Jan 19 at 20:59
7
\$\begingroup\$

20. Charcoal, 30 bytes

I⁺²⌕⪪”)¶q⁹1&¡⍘DλK⟦l∧NHz¿”²…⮌S²

Try it online! Link is to verbose version of code. Works by taking the last two digits of the user ID and looking it up in a table generated by splitting a compressed string into pairs of characters. (Taking the first two digits doesn't work because there are several repeats.) A few variants are possible by spending an extra byte or two on the table which are offset by the saving from not having to offset the resulting index. Unfortunately there are overlaps between adjacent user IDs which means that the string has to be split into pairs of characters to find the index accurately, although one byte of this is offset by not having to halve the resulting index. Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11
44718 -> 12
 9481 -> 13
78123 -> 14
64121 -> 15
41565 -> 16
52210 -> 17
91569 -> 18
 3852 -> 19
17602 -> 20
\$\endgroup\$
6
\$\begingroup\$

13. Python 3, 45 bytes

lambda n:ord('ehlkacfbdgimj'[n%209%80%13])-96

Try it online!

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11
44718 -> 12
 9481 -> 13
\$\endgroup\$
4
  • \$\begingroup\$ Replace the string literal by a bytes literal to remove the ord \$\endgroup\$ – mic_e Jan 20 at 13:57
  • \$\begingroup\$ @mic_e Nice idea but this isn't code golf, just have to weigh in at 50 bytes or less. \$\endgroup\$ – Noodle9 Jan 20 at 15:00
  • \$\begingroup\$ Your shorter ID makes it less straight-forward for some approaches. :) \$\endgroup\$ – Kevin Cruijssen Jan 20 at 15:14
  • 2
    \$\begingroup\$ @KevinCruijssen Yeah, this competition reminds me just how long ago I joined SO! :D \$\endgroup\$ – Noodle9 Jan 20 at 15:18
6
\$\begingroup\$

15. 05AB1E, 42 bytes

This is based on the Chinese remainder theorem. Since all divisors need to be pairwise coprime, we use the nth prime for each user id n.

•3hy₁Ω=”Ó6™≠ò“êS’>₄?Θ¢9?Âγ”J4 %œ~ª‰fÃα•IØ%

Try it online!

•3hy...fÃα• is the large compressed integer 1369130535064223821413376960561972089702936948491908270885271972462351716275011314738309.
I pushes the input, Ø takes the n-th prime and % takes the large compressed integer modulo the prime number.

The big constant is generated with the ChineseRemainder builtin from the Wolfram Language: Try it online!

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11
44718 -> 12
 9481 -> 13
78123 -> 14
64121 -> 15

By using the closest prime to n/349 instead of the nth prime this can be golfed to 24 bytes:

•1RMζ)šÙ&KxγŸÏäí•IƵù/Ån%

Try it online!

•1R...äí•         # compressed integer 5437583563235532232480395276083021
         I        # push the input
          Ƶù/     # divide by 349
             Ån   # find the nearest prime
               %  # modulo the large integer with the prime
\$\endgroup\$
6
\$\begingroup\$

17. MathGolf, 41 40 bytes

☼+░╞╪2<W48R087`9H4957V6984♂Y☻5405]y2/├=)

Try it online.

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11
44718 -> 12
 9481 -> 13
78123 -> 14
64121 -> 15
41565 -> 16
52210 -> 17

Explanation:

☼+           # Add 100000 to the (implicit) input-integer
  ░          # Convert it to a string
   ╞         # Remove the first digit (the 1)
             # (the `☼+░╞` is used to convert the input 9481 to "09481",
             #  and at the same time convert any other input-integer to a string)
╪            # Rotate it once towards the right
 2<          # Leave only the first two characters
   W48R087`9H4957V6984♂Y☻5405
             # Push the following integers to the stack
             # (where ` duplicates the top two items, thus 8,7):
             #  35,4,8,29,0,8,7,8,7,9,19,4,9,5,7,34,6,9,8,4,10,37,16,5,4,0,5
    ]y       # Wrap the stack in a list, and join it together
      2/     # Split it into parts of size 2
        ├    # Pop the left item from the list, and push it to the stack
             # (which is the value we calculated at first)
         =   # Get its 0-based index in the list
          )  # And increase it by 1 to make it a 1-based index
             # (after which the entire stack is output implicitly as result)
\$\endgroup\$
5
\$\begingroup\$

3. APL (Dyalog Unicode), 7 bytes

4|∘⍎3⊃⍕

Try it online!

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3

Explanation:

4|∘⍎3⊃⍕
       ⍕  ⍝ Convert to string
     3⊃   ⍝ Pick the third digit (5, 2, or 7)
   ⍎      ⍝ Execute (make the digit a number again)
4|        ⍝ Mod 4
\$\endgroup\$
5
\$\begingroup\$

4. C# (.NET Core), 16 bytes

n=>2-n%2+n%100%7

Try it online!

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4

Lucky coincidence that

  • All IDs except the first are even

  • Last 2 digits of the first 2 IDs are divisible by 7

  • Last 2 digits of the second 2 IDs are 1 and 2 mod 7 respectively

\$\endgroup\$
3
  • \$\begingroup\$ @user Thanks for the tip. This isn't a code golf question so I didn't really care about the code length but I'll amend it. \$\endgroup\$ – 79037662 Jan 19 at 16:51
  • \$\begingroup\$ Well, your core answer is great as it is, but it's tagged code golf. Also, you need to add 4. to your answer header (I forgot it too) \$\endgroup\$ – user Jan 19 at 16:52
  • 1
    \$\begingroup\$ You're right of course, I meant that there wasn't a scoring criterion with length of code as the score. \$\endgroup\$ – 79037662 Jan 19 at 16:53
5
\$\begingroup\$

5. Zsh, 25 bytes

<<<$[$1&7?(4+${1:4})%6:3]

Try it online!

(4 + ${1:4}) % 6 works for every ID but 95792. But, 95792 is the only ID divisible by 8, so a ternary with $1 % 8 as the condition works.

58563  ->  3 ? (4 + 3) % 6 : 3  ->  7 % 6  ->  1
80214  ->  6 ? (4 + 4) % 6 : 3  ->  8 % 6  ->  2
95792  ->  0 ? (4 + 2) % 6 : 3  ->             3
89930  ->  2 ? (4 + 0) % 6 : 3  ->  4 % 6  ->  4
86147  ->  3 ? (4 + 7) % 6 : 3  -> 11 % 6  ->  5

The more boring 24 byte answer, based off of @pxeger's

a=8059
<<<$a[(i)${1[2]}]
\$\endgroup\$
2
  • 1
    \$\begingroup\$ I'm sorry my ID fails your shorter function :( \$\endgroup\$ – user Jan 19 at 17:31
  • 1
    \$\begingroup\$ @user You're just a special case :P \$\endgroup\$ – GammaFunction Jan 19 at 17:33
5
\$\begingroup\$

12. C (gcc), 50 bytes

int f(int n){return"DJHABILFCGKE"[n%60%50%12]-64;}

Try it online!

This code could be golfable. But this question is not taged . So let's leave it warning free.

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11
44718 -> 12
\$\endgroup\$
5
\$\begingroup\$

18. 05AB1E, 45 bytes

•1ααāš®‚wA%|ʒη¦%áY攀…FKΘćRɱnG’*AÂÉζ•5ôíÌskÌ

Try it online!

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11
44718 -> 12
 9481 -> 13
78123 -> 14
64121 -> 15
41565 -> 16
52210 -> 17
91569 -> 18

The compressed number is each user ID minus 2, reversed, and joined together (except 9481 which is changed into 97490, and 58563 which is not included). splits it, εR} reverses it, sk returns the index of the input in the list, and Ì adds 2.

\$\endgroup\$
5
4
\$\begingroup\$

14. Stax, 48 bytes

"&,R>&N_QbmO.%:VUVh5m@x~|LVju(bWJij<$"%98542|EI^

Run and debug it

You thought the time for trivial solutions was over? Fool!

Well, maybe not entirely trivial. But the nontrivial part was generated by Stax's array literal generator. The only thing I added is the I^, which means "find the index of the input number in the array and increment it".

The code could be packed, but this is not .

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11
44718 -> 12
 9481 -> 13
78123 -> 14
\$\endgroup\$
4
\$\begingroup\$

16. C# (.NET Core), 47 bytes

Not creative... just a basic mapping. Constants came from experimentation

x=>" +$Q2('%OINFA;4@0".IndexOf((char)(x%49+35))

Try it online!

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11
44718 -> 12
 9481 -> 13
78123 -> 14
64121 -> 15
41565 -> 16
\$\endgroup\$
1
  • 1
    \$\begingroup\$ The average minimal modulo \$m\$ to have this working for 16 distinct random numbers in \$[10000...100000]\$ seems to be close to \$51\$. So the odds are slightly in our (your) favor so far. :-) \$\endgroup\$ – Arnauld Jan 20 at 11:32
3
\$\begingroup\$

10. Python 3, 44 bytes

lambda x:'973.84.612..5a'[int(x[0]+x[4])%15]

Try it online!

Input is taken as a decimal string and returned as a hexadecimal string

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10  (displayed as `a` in this case)

Explanation

Takes the first and last digits, mod 15 and indexes into a string lookup table. This approach won't work for too much longer, but could probably be stretched to 20 or so in a language with more flexible string->int conversion, like Javascript, PHP, or Perl.

\$\endgroup\$
3
\$\begingroup\$

11. 05AB1E, 30 bytes

•γ¤š×Pγ…þiðþ–
çô&`)½c©2è•5ôsk>

Try it online!

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11

•...•5ôsk>  # trimmed program
        k   # get 0...
         >  # plus 1...
        k   # -based index of...
       s    # implicit input...
        k   # in...
•...•       # 5856380214957928993086147978579854195594707454561394066...
      ô     # split in pieces of...
     5      # literal
            # implicit output
\$\endgroup\$
3
\$\begingroup\$

19. Befunge-93, 45 bytes

"0$>K"&\%\%\%\%1g\-.@
/1C274=B8?A5>:/@;3</96

Try it online!

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11
44718 -> 12
 9481 -> 13
78123 -> 14
64121 -> 15
41565 -> 16
52210 -> 17
91569 -> 18
 3852 -> 19

There's a raw low-ASCII byte (decimal 25) between the 0 and the $.

This computes str[input%75%62%36%25] - '0', where str is the string on the second line of the program.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Lowest user ID so far! ;) \$\endgroup\$ – Arnauld Jan 22 at 19:16
3
\$\begingroup\$

21. Pyth, 49 50 bytes

(answer ID & 753) % 38 happens to be unique for every answer so I just use that to make a lookup table.

C@" \r	     
          "%.&753Q38

The string in python repr format: ' \r\x14\x01\x02\t\x04\x06 \n \x05\x0b\x0f\x13 \x08 \x10 \x12\x0c \x03 \x11 \x0e \x07'

Updated list:

58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
70745 -> 9
45613 -> 10
94066 -> 11
44718 -> 12
 9481 -> 13
78123 -> 14
64121 -> 15
41565 -> 16
52210 -> 17
91569 -> 18
 3852 -> 19
17602 -> 20
75429 -> 21

+1 byte because Python doesn't like carriage returns on their own apparently

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ @Arnauld Let me double check, I copy pasted it in to TIO from a school laptop and who knows what it did \$\endgroup\$ – Citty Apr 9 at 13:03
  • 1
    \$\begingroup\$ Fixed it, the carriage return was being translated to a newline \$\endgroup\$ – Citty Apr 9 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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