12
\$\begingroup\$

As we all know, most Pokemon are created by combining some English (or Japanese) words; these words are the Pokemon's "etymology." For example, "charmander" is "char" and "salamander" put together.

Your task is, given a Pokemon's etymology and number, output the original Pokemon name. A short answer will be able to compress the 890 Pokemon into much fewer characters by exploiting the fact that the etymologies and the names themselves use mostly the same characters.

Input: The Pokemon number, and an array/list of etymologies, all lowercase

Output: The Pokemon's name, also lowercase

The full list of test cases can be found here: https://pastebin.com/B3rRdiPn. Each line is a test case with the format:

<pokemon number>;<comma separated etymology list>;<pokemon name>

This list was created from https://pokemondb.net/etymology by running the following code:

let collectedRows = [];
let rows = $(".data-table tr").slice(1)
let isOddPrev = false;
// Replacements due to typos, remove 'palindrome' since girafig doesn't come from the word 'palindrome', 'palindrome' is just a descriptor
var repl = {"anacondo": "anaconda", "armadilo": "armadillo", "[palindrome]": ""}
rows.each((_, row) => {
  let isOdd = row.classList.contains("odd");
  let etym = $(row).find(".cell-etym-word").text().toLowerCase();
  if (repl.hasOwnProperty(etym)) etym = repl[etym];
  if (isOdd !== isOddPrev) {
    collectedRows.push({name: $(row).find(".cell-name").text().toLowerCase(), etymology: [etym], num: parseInt($(row).find(".cell-num").text().replace(/\s/g, ''), 10)});
  } else {
    collectedRows[collectedRows.length - 1].etymology.push(etym);
  }

  isOddPrev = isOdd;
});

// Output:
collectedRows.map(pokemon => pokemon.num + ";" + pokemon.etymology.join(",").replace(/\,$/, '') + ";" + pokemon.name).join("\n")

Examples:

The full list of test cases can be found at the pastebin link, but here are some example inputs and outputs:

1, ['bulb', '-saur'] --> 'bulbasaur'
122, ['mr.', 'mime artist'] --> 'mr. mime'
29, ['nidoru' ,'rhino', '♀'] --> 'nidoran♀'
16, ['pigeon'] --> 'pidgey'
17, ['pigeon'] --> 'pidgeotto'
23, ['snake'] --> 'ekans'

Note that due to 'nidoran♀' and its family, you need to be able to handle input/output in UTF-8.

The winner is the entry with the highest accuracy, with ties broken by code length. In practice, this means that the challenge is code-golf -- you need to get 100% accuracy to be a competitive entry -- since you can trivially create a lookup table, but feel free to post a sub-100% accuracy answer if you think it does something creative (someone else might extend it to handle the edge cases).

If you wish, you may also include a data file, and the number of bytes of that file is added to your byte count. This is just if you want to keep your code and data separate.

\$\endgroup\$
7
  • \$\begingroup\$ Why do we take the pkmn number as input? \$\endgroup\$
    – RGS
    Commented Apr 6, 2020 at 20:26
  • 5
    \$\begingroup\$ @RGS It looks like the etymology doesn't resolve uniquely to a name, 16, ['pigeon'] --> 'pidgey', 17, ['pigeon'] --> 'pidgeotto'. So, sometimes you need the number. \$\endgroup\$
    – xnor
    Commented Apr 6, 2020 at 20:28
  • 4
    \$\begingroup\$ @xnor maybe it would be interesting to only take etymology as input and let the solutions return any of the possible names when there are several Pokémon with the same etymology \$\endgroup\$
    – RGS
    Commented Apr 6, 2020 at 20:37
  • 2
    \$\begingroup\$ Waiting for a Pyke solution. \$\endgroup\$ Commented Apr 7, 2020 at 4:28
  • 3
    \$\begingroup\$ Seeing as there are already solutions, it's probably too late to want to correct this, but Slowpoke and Slowbro have weirdly repeated etymologies \$\endgroup\$
    – DanTheMan
    Commented Apr 7, 2020 at 4:35

4 Answers 4

7
\$\begingroup\$

JavaScript (Node.js 11.7+), 100%, 2094 bytes

Same as below, with the data file compressed with Brotli instead of zlib.

n=>a=>(require('zlib').brotliDecompressSync(require('fs').readFileSync('a'))+'').split`/`[n-1].replace(/\d.\d?/g,([i,p,l])=>a[i].substr(p,++l||9))

Try it online! (not working on TIO)


JavaScript (Node.js), 100%,  2176 2158  2151 bytes

This is similar to the self-contained version below but uses an external data file of 2010 bytes named 'a'. The TIO link generates a local copy of this file.

The final size was computed according to the rules for scoring multiple files:

$$2010+140+1=2151$$

n=>a=>(require('zlib').inflateRawSync(require('fs').readFileSync('a'))+'').split`/`[n-1].replace(/\d.\d?/g,([i,p,l])=>a[i].substr(p,++l||9))

Try it online!


JavaScript (Node.js), 100%,  2701 ... 2359  2356 bytes

Takes input as (id)([etymology0, etymology1, ...]).

The source contains many unprintable characters.

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O|72ri18/tiFoPYF`WenWH3sXZ_YuaYoZYccV/ccV>QSt18DME2,]~Jite^3^3]aws`0UlH)FT3ZR/fooUYs{6/alo0U0P&k^5GGLLL4ZXVkC3kkC222lgyem/beheeyem[D<Z~wYxHXxo24MQQ2rk~fooXZ3iTQOQRJlHRK^IWH3]/doQ?4F23]ENSkZWzZASZ$4am~kVm~ormM}53aR}53BGRNK2ieD]Dby~sby^5AG<`RD[O];M3sQR+++OR]ENe<V&xNMK4XI^4kFVeMerQE>OBY082a?50aYv`[5X0TneRKYg`*LkiEMSa17	M/xZ3eas/Z3lt25/zy`Yncie~aA/VRKW(<Z~pC3}5Xk2k_^3/yC3^52?7Wj(Xk(]R8Yc0PGO321_{T4iO[[|5OO3H/fo`ONW23RR~ul/!01_/H5072RaWey]D]GYos`/py=17@Vu~: `_D?2FIQ~de`Wkyu]K/d`4T-o-oL4-o3o~ V4iSg{UYg(]G]<V/xkH3eeaXrUNXcT2zC$[[_a=ka[7nYaZ	Qy/U5`_OK{7{6kwZB{6GG_lerO&t{VWW=/dF`Q;2VXIRFolQnRGRDWk{P07[2%>SskVB3<aSanremZ&@1]3~m`SgC/pZ2V]3%5'd~ riI~rig17K|Vmie/fF,Ym_RisP2eJT2%~f,A~zZWozZ~vZWovZAXVZQ/zaciU/za0UzTJtus~/}W1|Y1{S1`10_}0^J1]}1[|0Z11Y~3X~2W~4V12U0!03S~5R}2Q}3P04O|1N{1M|2L)01K|3J~6I13H05G{0FU2E{2D}4C14B{3A^1@20?/`>{4=0V<~7;YP,15+[4*[3)/k(a`&~i%|4$X`#/P3`_!2Ti`J`_3U3~eYk{5_4/T4~ `Z;20006/wa/09/s^2}6_2	][16na/eanur~tWi")=>i<127?g(a,i+1,/[\r\n "'\--:\\a-z]/.test(c=Buffer([i]))?s:(l=s.split(c)).join(l.pop())):s.split`/`[n-1].replace(/\d.\d?/g,([i,p,l])=>a[i].substr('0x'+p,l||9))

Try it online!

How?

Each name is encoded as a sequence of sub-strings from the etymology words, with some possible hard-coded characters in between.

Example:

For the first name, we are given:

n = 1, a = ['bulb', '-saur']

The name bulbasaur is first encoded as 004a114, which is interpreted as:

'004' -> a[0].substr(0, 4) -> 'bulb'
'a'   -> hard-coded character 'a'
'114' -> a[1].substr(1, 4) -> 'saur'

But the length of the sub-string is omitted whenever this is possible without resulting in any ambiguity. When the length is omitted, the decoder assumes that the word must be read to its end.

Both lengths can be omitted in this case, so the final encoding is:

00a11

All the 890 encoding sequences are concatenated together, using / as a separator. This results in a string with a lot of repeated patterns which can be efficiently crushed:

00a11/00211/00412/00314/00313/00311/00514/00210324/00414/006e/00310/.../za001z03/005tus
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Since the etymology often follows the order of appearance in the name, I wonder if the etymology index can be omitted, e.g bulbasaur is 0a1? \$\endgroup\$ Commented Apr 7, 2020 at 4:55
  • \$\begingroup\$ @SurculoseSputum This is an interesting idea, but I was not able to successfully implement it so far. \$\endgroup\$
    – Arnauld
    Commented Apr 7, 2020 at 9:36
  • \$\begingroup\$ You can save a byte with ++l||9. \$\endgroup\$
    – Shaggy
    Commented Apr 7, 2020 at 14:08
  • \$\begingroup\$ @Shaggy Yes, I actually have a pending 140-byte version including this optimization. I was waiting a bit for a slightly more significant saving, but I'm not working on it anymore so I will probably commit it. \$\endgroup\$
    – Arnauld
    Commented Apr 7, 2020 at 14:19
4
\$\begingroup\$

Python 3, 2526 ... 2485 2477 bytes

import bz2,zlib,base64
b=base64.b85decode
p=bz2.decompress(b('LRx4!F+o`-Q(59BF!%rhj7R`*0Ds_61b*t7X+T7%iw!XbsxUw_05wnA5{ieYKr{d~PxKN}nvw5(BOjwtq%XftFY)%vlw$tuZI%9;4^7W^?|qN$^KHzUfTa1Tr63Y7r1jva6}^`q2S@hzE%f$eIEbHP$OqG_3SuF>V&&a2$k(oE#{VBmKW+Svm$v*~C^qWuF)k0y?|H~yTPf~!?wrgjhb&<eM^-^OI;(1`q-?Z<qzNrohfQ{Dj81Xiau!gFnMm=j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).decode().split('%')[n-1]+e[len(e)-int(p[n*2-1]):]

Try it online!

Based on idea of @dingledooper (thanks!), but making it a step further by using the longest common suffix to help as well. Also used zlib & base85 to further reduce size a bit.

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

Pyke, 100%, 835 bytes

Sorry folks, Pyke contains a built-in Pokémon dictionary. Unfortunately, it only contains up to #802: marshadow, so 88 names had to be hard-coded.

Should work for all inputs, but the TIO environment seems to have a slightly different version of Pyke than on the "Pyke Interpreter" website, so inputs greater than 802 only work on the latter (see below).

Q0@802>"poipole,naganadel,stakataka,blacephalon,zeraora,meltan,melmetal,grookey,thwackey,rillaboom,scorbunny,raboot,cinderace,sobble,drizzile,inteleon,skwovet,greedent,rookidee,corvisquire,corviknight,blipbug,dottler,orbeetle,nickit,thievul,gossifleur,eldegoss,wooloo,dubwool,chewtle,drednaw,yamper,boltund,rolycoly,carkol,coalossal,applin,flapple,appletun,silicobra,sandaconda,cramorant,arrokuda,barraskewda,toxel,toxtricity,sizzlipede,centiskorch,clobbopus,grapploct,sinistea,polteageist,hatenna,hattrem,hatterene,impidimp,morgrem,grimmsnarl,obstagoon,perrserker,cursola,sirfetch'd,mr. rime,runerigus,milcery,alcremie,falinks,pincurchin,snom,frosmoth,stonjourner,eiscue,indeedee,morpeko,cufant,copperajah,dracozolt,arctozolt,dracovish,arctovish,duraludon,dreepy,drakloak,dragapult,zacian,zamazenta,eternatus"\,cQ0@803-@&Q0@~_+1-.ol1|

Try it here! (This site doesn't seem to support unicode, so output for nidoran♀ will be in UTF-8)

Try it online! (Supports unicode, but throws an error for inputs > 802)

Takes input in the form [1, "bulb", "-saur"]

Some relevant portions of the program:

Q0@            

Read from STDIN, ignoring everything besides the pokemon number

Q0@802>...&

IF (pokemon #) > 802, Do the following:

"poipole,naganadel..."

- Using this long string of hardcoded names,

\,c              

-- split on commas, and

Q0@803-@        

-- return the name at index ((pokemon #) - 803)

Q0@~_+1-...|

ELSE: Find the index of this pokemon in the dictionary

.o          

- Lookup in the built-in pokemon dictionary, and:

l1         

- convert to lowercase, implicitly print

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

Python 3, 100%, 3817 ... 2463 2351 bytes

import base64,bz2,re
def f(n,e):
 s=re.findall("[A-Z].+?(?=[A-Z])",str(bz2.decompress(base64.b85decode("LRx4!F+o`-Q(2lYjJyB>_?>`2gMW}e@IU|m@L&gzfB<{l>MaducV>;xcV1v3r}_v9qd}l1g$bb0WFnp>O&STHDd{yaqyPYlr~6YAQwdMh*(7?5KmarbspRyU5D6YB>Ux_~Kpvn20BND4Mk62^05mXaen^xm000000ENyXhobxV`;X?{ExyPLkgLKDP|*Q^?o*e5XuP4M=5UaiAd|`2;!L-!vGCJPj#;Mo=2>TVCBV{l6DI6B_r0dGFBRQ-O|~`xNM7ayY%9|*JDHKx)H%`3m$P%bfxU(EeEGzleQ$#&o^1*0>`mQyWinz&K_h&|r)n^J<>jzrwUxNpN$qXir0}FVs_7L(Ks|=pmD2iIahTy>RB*k9#U=BSIWVqS3gGbVZpVtyD8dEs&<v#@cP}dhn`W7qib`>cvCEjl7e+vZP!cd9feP7KUJ||~0FQFad}w6bGbS;17~RfNW=AZ-?8t28AOz_wt~OR85Loar%*#lVF{BpPkTAlKBBJq&5IIzogmT3wP=ZP{!d>aETG<_DSc2Oj4duuj%a?ggAaH<lR3|AC9N>Wyq;np^W5Gyus`ED9MYY}3laCeQ@R052^8Lt6chhHS=PKG_o@*~ICBX~8XnxM69}KpBRk}!|Nkn*aP*I+cKKWij;l3&FfZofSuJl}P%9C^dABC%JEw(S#R(||vwYR%OltbAF<bRs2UeKzeXleyw=czoWGHjSn^SmprWPH?|!-=07#O)v9FyZb)D!mGeg_aEbQnWd~Sv^0$(U>TLiQx_d0ZJEj?In+L@`K%YQUM1cbI1*C-ukR(DngIFmkJ^qE)Dc7>Wf?`7`YWLwM+J3Hpu`;F&p=WjHW=<cygYHc+}GOFgXO0=*q=k*RxL<?d{EH8V4g`oTFz#A1JX|L%1mW4s9(}kh|5%etRW3y*^(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P@&gj9>5W^oRe^l@a-MKjx!_Em$F2!;9_1iF}v7FOAU5MhebG!cm!#tDiAHx_=BBoyR~nT-<02#y;N1qH_>8^t3Gu2k+kP#9cRS>VnNLqLE|Fyulvo#`c=FH6J$2A-0V!(nsHf$#pb$SzC+bx%8>H$mCL5MtK&@WCh^k#Bi<=$%9ljrqSIqYVXCLeT0UO8{)!sRB>f->^P%M|mf^+&6ALwl)hsRm$4<rgGU<1DfY8|KjdQrwS4iMiG~Q"))))[n-1]
 return e[:ord(s[0])-65]+s[2:]+e[len(e)-int(s[1]):]

Try it online!

Explanation

We could print all of the Pokemon with just the number, but the etymology allows us to improve the compression algorithm. Take the first input: 1;bulb,-saur;bulbasaur. The first etymology bulb and the actual Pokemon have a common prefix. Most Pokemon in the list also have this property. So instead of compressing the entire name of the Pokemon, we only compress the right half of it (asaur in the example), starting from the longest common prefix of it and the first etymology. Then for the left half we can just directly take a prefix of the first etymology (bulb in the example). We also precompute the longest common suffix to further reduce the size. Then, we will encode the string like this: 44a. The first and second characters represent the longest common prefix and suffix. The rest represent the rest of the characters not accounted.

\$\endgroup\$
2
  • \$\begingroup\$ I think changing base64 to base85 could shave a few hundred bytes? \$\endgroup\$
    – newbie
    Commented Apr 7, 2020 at 1:23
  • \$\begingroup\$ Good point, I didn't even know that existed! :P \$\endgroup\$ Commented Apr 7, 2020 at 1:28

Your Answer

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

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