| Bytes | Lang | Time | Link |
|---|---|---|---|
| 050 | JavaScript ES6 | 230727T095146Z | Arnauld |
| 061 | C gcc | 230727T082011Z | Peter |
| 105 | Wolfram LanguageMathematica | 230728T141444Z | 138 Aspe |
| 053 | Ruby | 230729T003018Z | Level Ri |
| 078 | Go | 230728T125914Z | bigyihsu |
| 051 | Scala 3 | 230728T092014Z | t9dupuy |
| 237 | Wenyan 文言 | 230727T113509Z | alephalp |
| 3060 | Nibbles | 230727T131358Z | Dominic |
| 051 | Charcoal | 230727T055208Z | Neil |
| 033 | Vyxal | 230727T083406Z | The Thon |
| 032 | Thunno 2 | 230727T080946Z | The Thon |
| 033 | 05AB1E | 230727T074916Z | Kevin Cr |
| 060 | Python | 230727T052306Z | SuperSto |
JavaScript (ES6), 50 bytes
Expects two code points as (a)(b).
a=>b=>"紫騮靘熏X綠黻紅硅黯碧"[a*b%25%11]
How?
Short modulo chains exist for all simple commutative operations (addition, multiplication, XOR and even OR). The benefit of using a multiplication is that no parentheses are required.
It's also interesting to note that we still have enough information when reducing both code points modulo 9:
a=>b=>"XX碧紫紅黯靘黻X綠X硅騮XX熏"[a%9^b%9]
Try it online! (53 bytes)
C (gcc), 61 bytes
f(a,b){a=L" 碧紅騮熏綠硅紫黯黻靘"[abs(a-b)%90%11];}
Port of @SuperStormer's Python submission
Thanks to @Neil for knowing how to print multibyte characters, and to @Kevin Cruijssen for pointing out that my byte count was wrong.
Wolfram Language(Mathematica), 105 bytes
Port of @SuperStormer's Python answer in Mathematica.
Golfed version, Try it online!
105 bytes, it can be golfed much more.
f[a_,b_]:=FromCharacterCode@ToCharacterCode["碧紅騮熏綠硅紫黯黻靘"][[Mod[Mod[Abs[a-b],90],11]]]
Ungolfed version. Try it online!
f[a_, b_] :=
FromCharacterCode[
ToCharacterCode["碧紅騮熏綠硅紫黯黻靘"][[((Abs[a - b]~Mod~ 90 )~Mod ~11)]]];
repl = {{"靑", "赤", "靘"}, {"赤", "黃", "熏"}, {"黃", "白", "硅"}, {"白", "黑",
"黻"}, {"黑", "靑", "黯"}, {"靑", "黃", "綠"}, {"黃", "黑", "騮"}, {"黑",
"赤", "紫"}, {"赤", "白", "紅"}, {"白", "靑", "碧"}};
Table[a = repl[[i, 1]]; b = repl[[i, 2]]; c = repl[[i, 3]];
res = f[ToCharacterCode[a][[1]], ToCharacterCode[b][[1]]];
Print[a, " ", b, " ", c, " ", res], {i, Length[repl]}];
Ruby, 53 bytes
->n{"紅熏紫 碧綠黯硅靘 黻騮"[n.sum%23%13]}
A function which Takes a string with the two input codepoints, finds a checksum (which for some reason is always even) and performs a mod-fold to hash it down to a number 0..12. This is then used as in index to look up in a string. The output is then returned as a single character.
The imperfect hash means there are 3 wasted spaces in the string, but that only counts as 3 bytes total (the Chinese characters on the other hand are 3 bytes each.)
Scala 3, 51 bytes
a=>b=>"黻綠黯熏紅紫硅碧騮靘"(a*b%6231%10)
Same modulo trick as @SuperStormer but uses multiplication instead.
Wenyan (文言), 237 bytes
-33 bytes thanks to @tsh.
吾有一術名之曰色欲行是術必先得二數曰「甲」曰「乙」乃行是術曰加甲以乙除其以百六六所餘幾何除其以十一所餘幾何夫『靘黯碧熏硅硅紫紅黻綠』之其乃得矣是謂「色」之術也
Expects two code points.
Based on @Arnauld's Javascript answer, but uses (a+b)%166%11 instead of a*b%25%11, because Wenyan is 1-indexed.
You can try it on this Online IDE. Here is a full test program:
吾有一術名之曰色欲行是術必先得二數曰「甲」曰「乙」乃行是術曰加甲以乙除其以百六六所餘幾何除其以十一所餘幾何夫『靘黯碧熏硅硅紫紅黻綠』之其乃得矣是謂「色」之術也
有數三萬八千七百三十七。名之曰「靑」。
有數三萬六千一百九十六。名之曰「赤」。
有數四萬零六百四十三。名之曰「黃」。
有數三萬零三百三十三。名之曰「白」。
有數四萬零六百五十七。名之曰「黑」。
施「色」於「靑」於「赤」。書之。
施「色」於「赤」於「黃」。書之。
施「色」於「黃」於「白」。書之。
施「色」於「白」於「黑」。書之。
施「色」於「黑」於「靑」。書之。
施「色」於「靑」於「黃」。書之。
施「色」於「黃」於「黑」。書之。
施「色」於「黑」於「赤」。書之。
施「色」於「赤」於「白」。書之。
施「色」於「白」於「靑」。書之。
Nibbles, 31 30 bytes (60 nibbles)
Edit: -1 byte thanks to xigoi
=%!=$@90:`D 40960 $ 1c179f3cec8cb05803cd69a25df3d95bf5d7758
Port of SuperStormer's Python answer - upvote that.
Input and output as Unicode points.
=%!=$@90:`D 40960 $
`D # interpret the appended data
40960 # in base 40960
# (so generates 10x 2-byte values);
: $ # append the input
= # and index into this list using
!= # absolute difference
$@ # of inputs
% 90 # modulo-90
Nibbles, 44 bytes (88 nibbles)
=%!=$@90.`/3`D256+' '$ c78287c79465c9888ec7666fc79680c78165c7948bc99b8fc99b9bc97d7858
Input and output as Chinese characters.
Charcoal, 55 51 bytes
F²⊞υ﹪﹪℅S³¹¦⁵℅I§⪪§⪪”)‴φ<ΦηA∧⌊✂⮌.\`P⁷⸿⁼DT⟦8'R&C”¶⌊υ⁵⌈υ
Try it online! Link is to verbose version of code. Explanation:
F²⊞υ﹪﹪℅S³¹¦⁵
Input the code points and reduce them modulo 31 and 5 to get them into the range 0-4.
℅I§⪪§⪪”)‴φ<ΦηA∧⌊✂⮌.\`P⁷⸿⁼DT⟦8'R&C”¶⌊υ⁵⌈υ
Look up the resulting character in a compressed lookup table.
A port of @SuperStormer's method is also 51 bytes:
§ 碧紅騮熏綠硅紫黯黻靘﹪↔⁻℅S℅S⁹⁰
Attempt This Online! Link is to verbose version of code. (TIO unnecessarily quotes the string literal, costing three bytes.)
Vyxal, 33 bytes
ε90%»æ↲‡ẇf;ƈ0£Xġ'ɾ[c₆⟨OɖaA»S5ẇ0pi
Port of @SuperStormer's Python answer. I/O as codepoints.
Explanation
ε90%»...»S5ẇ0pi # Implicit input
ε # Absolute difference
90% # Mod 90
»...»S # Compressed number
5ẇ # Split into chunks of length 5
0p # With a 0 prepended
i # Index into the list
# Implicit output
Thunno 2, 32 bytes
ṛ90%»æḳṫƈe:÷/ċWƊ&ıZbȥƙNỵ`@»Ṙ⁵0Ƥi
Port of @SuperStormer's Python answer. I/O as codepoints.
Just in case you're wondering:
Thunno 2, 39 bytes (UTF-8)
-A90%" 碧紅騮熏綠硅紫黯黻靘"i
Input as codepoints, outputs the character.
Explanation
ṛ90%»...»Ṙ⁵0Ƥi # Implicit input
ṛ # Absolute difference
90% # Mod 90
»...»Ṙ # Compressed number
⁵ # Split into chunks of length 5
0Ƥ # With a 0 prepended
i # Index into the list
# Implicit output
05AB1E, 33 bytes
α90%•MÚöć'wSlé∞‘cP₃$«¢Γå"α•5ô0šsè
I/O as codepoint integers.
Port of @SuperStormer's Python answer.
Try it online or verify all test cases.
Explanation:
α # Get the absolute difference of the two (implicit) input codepoint-integers
90% # Modulo-90
•MÚöć'wSlé∞‘cP₃$«¢Γå"α•
'# Push compressed integer 30887320053947029071321603078932043406874069938744
5ô # Split it into parts of size 5
0š # Prepend a dummy 0
s # Swap so the earlier abs(a-b)%90 is at the top of the stack
è # 0-based modular index it into this list
# (after which the result is output implicitly)
See this 05AB1E tip of mine (section How to compress large integers?) to understand why •MÚöć'wSlé∞‘cP₃$«¢Γå"α• is 30887320053947029071321603078932043406874069938744.
Since I was curious: using the actual unicode characters would result in an 18-character program, but it would be 40 bytes in UTF-8 encoding:
α90%" 碧紅騮熏綠硅紫黯黻靘"è
Input as codepoint integers, output as Chinese character.
Python, 60 bytes
-1 byte thanks to Neil
lambda a,b:' 碧紅騮熏綠硅紫黯黻靘'[abs(a-b)%90%11]
Takes input in Unicode codepoints (integers), and returns a string.
Explanation
Basically, the idea is to "hash" the 2 input values and index into a string of possible outputs. abs(a-b)%90%11 resulted in 10 different indexes for the 10 possible inputs. Generation script