Code Golf Asked by Arnauld on February 18, 2021
This is an answer-chaining 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.
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.
The first answer is written by user Arnauld (58563):
_=>1
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):
lambda n:2-n%2
Updated list:
58563 -> 1
123456 -> 2
This code returns 1 when given 58563 or 2 when given 123456.
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
Answered by Neil on February 18, 2021
"0$>K"&%%%%1g-.@
/1C274=B8?A5>:/@;3</96
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.
Answered by Lynn on February 18, 2021
•1ααāš®‚wA%|ʒη¦%áY攀…FKΘćRɱnG’*AÂÉζ•5ôíÌskÌ
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). 5ô
splits it, εR}
reverses it, sk
returns the index of the input in the list, and Ì
adds 2.
Answered by PkmnQ on February 18, 2021
☼+░╞╪2<W48R087879H4957V6984♂Y☻5405]y2/├=)
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
W48R087879H4957V6984♂Y☻5405
# Push the following integers to the stack:
# 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)
Answered by Kevin Cruijssen on February 18, 2021
Not creative... just a basic mapping. Constants came from experimentation
x=>" +$Q2('%OINFA;4@0".IndexOf((char)(x%49+35))
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
Answered by pinkfloydx33 on February 18, 2021
This is based on the Chinese remainder theorem. Since all divisors need to be pairwise coprime, we use the n
th prime for each user id n
.
•3hy₁Ω=”Ó6™≠ò“êS’>₄?Θ¢9?Âγ”J4 %œ~ª‰fÃα•IØ%
•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 n
th prime this can be golfed to 24 bytes:
•1RMζ)šÙ&KxγŸÏäí•IƵù/Ån%
•1R...äí• # compressed integer 5437583563235532232480395276083021
I # push the input
Ƶù/ # divide by 349
Ån # find the nearest prime
% # modulo the large integer with the prime
Answered by ovs on February 18, 2021
"&,R>&N_QbmO.%:VUVh5m@x~|LVju(bWJij<$"%98542|EI^
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 code-golf.
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
Answered by wastl on February 18, 2021
lambda n:ord('ehlkacfbdgimj'[n%209%80%13])-96
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
Answered by Noodle9 on February 18, 2021
int f(int n){return"DJHABILFCGKE"[n%60%50%12]-64;}
This code could be golfable. But this question is not taged code-golf. 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
Answered by tsh on February 18, 2021
•γ¤š×Pγ…þiðþ–
çô&`)½c©2è•5ôsk>
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
Answered by Makonede on February 18, 2021
lambda x:'973.84.612..5a'[int(x[0]+x[4])%15]
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)
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.
Answered by Beefster on February 18, 2021
-p
, $_=(a74a298635=~/./g)[$_%26%20%12]||1
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)
Answered by Nahuel Fouilleul on February 18, 2021
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+
.
Update list:
58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
98541 -> 7
95594 -> 8
Answered by xash on February 18, 2021
works due to Int64
overflowing to negative numbers
x->(x-8479)^6%5+5
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
Answered by MarcMush on February 18, 2021
a=80596
<<<$a[(i)${1[2]}]
Boring.
-1 by @GammaFunction
Updated list:
58563 -> 1
80214 -> 2
95792 -> 3
89930 -> 4
86147 -> 5
97857 -> 6
Answered by pxeger on February 18, 2021
<<<$[$1&7?(4+${1:4})%6:3]
(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]}]
Answered by GammaFunction on February 18, 2021
n=>2-n%2+n%100%7
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
Answered by 79037662 on February 18, 2021
4|∘⍎3⊃⍕
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
Answered by user on February 18, 2021
Answered by Razetime on February 18, 2021
Answered by Arnauld on February 18, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP