9
\$\begingroup\$

This challenge will be based on an R language trivia: every release is named and it's a reference to Peanuts comic strips (see here and here).

Task

Given a release name, output its number.

For reference, use the below list:

Great Pumpkin            2.14.0 
December Snowflakes      2.14.1 
Gift-Getting Season      2.14.2 
Easter Beagle            2.15.0 
Roasted Marshmallows     2.15.1 
Trick or Treat           2.15.2 
Security Blanket         2.15.3 
Masked Marvel            3.0.0 
Good Sport               3.0.1 
Frisbee Sailing          3.0.2 
Warm Puppy               3.0.3 
Spring Dance             3.1.0 
Sock it to Me            3.1.1 
Pumpkin Helmet           3.1.2 
Smooth Sidewalk          3.1.3 
Full of Ingredients      3.2.0 
World-Famous Astronaut   3.2.1 
Fire Safety              3.2.2 
Wooden Christmas-Tree    3.2.3 
Very Secure Dishes       3.2.4 
Very, Very Secure Dishes 3.2.5 
Supposedly Educational   3.3.0 
Bug in Your Hair         3.3.1 
Sincere Pumpkin Patch    3.3.2 
Another Canoe            3.3.3 
You Stupid Darkness      3.4.0 
Single Candle            3.4.1 
Short Summer             3.4.2 
Kite-Eating Tree         3.4.3 
Someone to Lean On       3.4.4 
Joy in Playing           3.5.0 
Feather Spray            3.5.1 
Eggshell Igloo           3.5.2 
Great Truth              3.5.3 
Planting of a Tree       3.6.0 
Action of the Toes       3.6.1 
Dark and Stormy Night    3.6.2 
Holding the Windsock     3.6.3 
Arbor Day                4.0.0 
See Things Now           4.0.1 
Taking Off Again         4.0.2 
Bunny-Wunnies Freak Out  4.0.3 
Lost Library Book        4.0.4 
Shake and Throw          4.0.5 
Camp Pontanezen          4.1.0 
Kick Things              4.1.1 
Bird Hippie              4.1.2 
One Push-Up              4.1.3 
Vigorous Calisthenics    4.2.0 

Rules

  • You may take input and output in any reasonable format (for output this includes a dot delimited string (as above), a string with other delimiter, a 3-element list etc.).
  • This is - usual rules apply.
\$\endgroup\$
2
  • \$\begingroup\$ Related, more related. \$\endgroup\$
    – pajonk
    Jun 30, 2022 at 6:50
  • \$\begingroup\$ I don't feel like this type of challenge was already overdone with the linked challenges, and this doesn't provide anything new. \$\endgroup\$
    – Wheat Wizard
    Jun 30, 2022 at 7:22

1 Answer 1

15
\$\begingroup\$

JavaScript (Node.js), 174 bytes

Returns a triplet \$[a,b,c]\$.

s=>[(n=Buffer("1M1rb2dX~N(jm8+2p~aL2fw[k~_)1F1sT2q3VSGx^~R7H~ue.v/~ytY2U~gl~O1W|6*3I5`2Z".replace(/\d/g,n=>10**n))[parseInt(s[9]+s,36)%901%126]+56)/42|0,n/6%7^13*(n<105),n%6]

Try it online!

Encoding

Here is the uncompressed lookup string.

Each version is encoded as a single character in the printable ASCII ranges \$[40\dots48]\$ and \$[70\dots124]\$. The first range is for 2.x.x and the second one for 3.x.x and 4.x.x.

The padding character in the lookup string is ~. Runs of 2 to 10 consecutive ~ are replaced with 1 to 9.

Note: We actually don't use ~ when decompressing. Each digit \$k\$ is instead expanded to \$10^k\$ (a 1 followed by \$k\$ 0's). And that's why the sub-string R~~~~~0~~H, which includes a meaningful 0, can be compressed as R7H, saving 2 more bytes.

To summarize:

ASCII Range Character range Meaning
40 - 48 ( to 0 version 2.x.x
49 - 57 1 to 9 compressed padding string
70 - 124 F to | version 3.x.x or 4.x.x
126 ~ single padding character

To turn a character \$C\$ into the version triplet \$[a,b,c]\$, we compute \$n=\operatorname{ord}(C)+56\$ and then:

$$\begin{align}&a=\lfloor n/42\rfloor\\ &b=\cases{ \lfloor n/6\rfloor\bmod7&if $n\ge105$\\ \left(\lfloor n/6\rfloor\bmod7\right)\operatorname{xor}13&if $n<105$ }\\ &c=n\bmod6\end{align}$$

\$\endgroup\$
1
  • \$\begingroup\$ Wow I admire the compression scheme used :D \$\endgroup\$
    – Marco
    Jul 3, 2022 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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