33
\$\begingroup\$

Input: an integer N between 1 and 151

Output: the Nth Pokemon.

Rules

  • You may use one data file.

  • You may not use any already made data decompression algorithms. This includes libraries and other programs.

  • Your program may not access files other than itself and your data file.

Scoring

Your score is the sum of the length of your code and data file.

Helpful Stuff

Here's a list of the first 151 pokemon separated by semicolons to help you generate your data file. Your output should exactly match the Nth entry of this line:

Bulbasaur;Ivysaur;Venusaur;Charmander;Charmeleon;Charizard;Squirtle;Wartortle;Blastoise;Caterpie;Metapod;Butterfree;Weedle;Kakuna;Beedrill;Pidgey;Pidgeotto;Pidgeot;Rattata;Raticate;Spearow;Fearow;Ekans;Arbok;Pikachu;Raichu;Sandshrew;Sandslash;Nidoran (f);Nidorina;Nidoqueen;Nidoran (m);Nidorino;Nidoking;Clefairy;Clefable;Vulpix;Ninetales;Jigglypuff;Wigglytuff;Zubat;Golbat;Oddish;Gloom;Vileplume;Paras;Parasect;Venonat;Venomoth;Diglett;Dugtrio;Meowth;Persian;Psyduck;Golduck;Mankey;Primeape;Growlith;Arcanine;Poliwag;Poliwhirl;Poliwrath;Abra;Kadabra;Alakazam;Machop;Machoke;Machamp;Bellsprout;Weepinbell;Victreebell;Tentacool;Tentacruel;Geodude;Graveler;Golem;Ponyta;Rapidash;Slowpoke;Slowbro;Magnemite;Magneton;Farfetch'd;Doduo;Dodrio;Seel;Dewgong;Grimer;Muk;Shellder;Cloyster;Gastly;Haunter;Gengar;Onix;Drowsee;Hypno;Krabby;Kingler;Voltorb;Electrode;Exeggute;Exeggutor;Cubone;Marowak;Hitmonlee;Hitmonchan;Lickitung;Koffing;Weezing;Rhyhorn;Rhydon;Chansey;Tangela;Kangaskhan;Horsea;Seadra;Goldeen;Seaking;Staryu;Starmie;Mr. Mime;Scyther;Jynx;Electabuzz;Magmar;Pinsir;Tauros;Magikarp;Gyarados;Lapras;Ditto;Eevee;Vaporeon;Jolteon;Flareon;Porygon;Omanyte;Omastar;Kabuto;Kabutops;Aerodactyl;Snorlax;Articuno;Zapdos;Moltres;Dratini;Dragonair;Dragonite;Mewtwo;Mew
\$\endgroup\$
  • \$\begingroup\$ Is Bubblegum allowed? \$\endgroup\$ – PyRulez Oct 28 '17 at 20:41
  • \$\begingroup\$ @PyRulez Yes, so long as you don't use any of its built-in data decompression. So good luck breaking SHA256. \$\endgroup\$ – cardboard_box Oct 29 '17 at 0:26
  • \$\begingroup\$ If our language has a builtin for returning the list of pokemon, can we use it without a byte addition? \$\endgroup\$ – caird coinheringaahing Oct 30 '17 at 19:20
  • \$\begingroup\$ @cairdcoinheringaahing If you're talking about pyke's builtin, I feel that goes against the spirit of the challenge, however I guess it would be non-competing anyway. \$\endgroup\$ – FlipTack Oct 30 '17 at 19:57
  • \$\begingroup\$ I just noticed this challenge, had written up the answer and then noticed the date for it :P I'm kind of disappointed I didn't get to use my language's one otherwise useless feature \$\endgroup\$ – Blue Jul 17 at 18:36
8
\$\begingroup\$

J (93 + 787 = 880)

Edit: other capitalisation method that capitalizes 'Mr. Mime' correctly.

Can probably be shortened, I've almost never written J before. It works on a similar principle as the PHP example.

You need the 'p' file in the same directory as you run this, the file can be downloaded from: http://frankenstein.d-n-s.org.uk/p. It is 787 bytes.

u:p-32*96<p*|.!.1[32=p=.(}.p#~(".1!:1[1)=+/\31=p=.#._5>\,#:a.i.1!:1<'p'){(97+i.26),a.i.'.()'' '

The file is encoded in a five-bit format, as follows:

0-25: A-Z
26: .
27: (
28: )
29: '
30: <space>
31: separator

The file also starts with a separator, to make the list 1-based.

The J code works as follows:

  • (97+i.26),a.i.'.()'' ': a string where the index N is the ASCII character
  • {: select from this list the values generated by the expression below
  • 1!:1<'p': read the 'p' file
  • ,#:a.i.: get the file as bits
  • _5>\: group the bits in groups of five
  • p=.#.: transform each group of bits into a number and assign to p
  • +/\31=p: a list of the size of p where each value N means the value at that position in p belongs to the N-th pokemon.
  • (".1!:1[1)=: read a number from the keyboard and see where in p the characters for that pokemon are.
  • }.p#~: look them up in p, and remove the first item (which is the separator).
  • p-32*96<p*_1|.(!.1)32=p=.: Assign the output to p again, and subtract 32 from p where p is bigger than 96 and to the right of a space. Which is cumbersome. According to the J documentation there should be a capitalize function but it's not there on my system.
  • u:: look them up as unicode.
\$\endgroup\$
  • 1
    \$\begingroup\$ I'm getting Ulbasaur for the first pokemon. Am I running it correctly? I've never used J before. Also, Mr. Mime should be capitalized. \$\endgroup\$ – cardboard_box Dec 4 '12 at 20:28
  • \$\begingroup\$ @cardboard_box: I've changed the capitalisation method so that Mr. Mime works (at the cost of 9 characters). The Ulbasaur was a typo in the data file, that has also been fixed. \$\endgroup\$ – marinus Dec 4 '12 at 21:46
  • \$\begingroup\$ It looks like the link is dead. \$\endgroup\$ – Erik the Outgolfer May 30 '18 at 14:16
23
\$\begingroup\$

Bash 1182 chars

read n;echo {Bulba,Ivy,Venu}saur Char{mander,meleon,izard} {Squi,Warto}rtle Blastoise Caterpie Metapod Butterfree Weedle Kakuna Beedrill Pidge{y,otto,ot} Rat{tata,icate} {Sp,F}earow Ekans Arbok {Pika,Rai}chu Sands{hrew,lash} Nido{ran%\(f\),rina,queen,ran%\(m\),rino,king} Clefa{iry,ble} Vulpix Ninetales {Jigglyp,Wigglyt}uff {Zu,Gol}bat Oddish Gloom Vileplume Paras{,ect} Veno{nat,moth} Diglett Dugtrio Meowth Persian {Psy,Gol}duck Mankey Primeape Growlith Arcanine Poliw{ag,hirl,rath} {A,Kada}bra Alakazam Mach{op,oke,amp} Bellsprout {Weepin,Victree}bell Tentac{ool,ruel} Geodude Graveler Golem Ponyta Rapidash Slow{poke,bro} Magne{mite,ton} Farfetch\'d Dod{uo,rio} Seel Dewgong Grimer Muk {Shelld,Cloyst}er Gastly Haunter Gengar Onix Drowsee Hypno Krabby Kingler Voltorb Electrode Exeggut{e,or} Cubone Marowak Hitmon{lee,chan} Lickitung {Koff,Weez}ing Rhy{horn,don} Chansey Tangela Kangaskhan Horsea Seadra Goldeen Seaking Star{yu,mie} Mr.%Mime Scyther Jynx Electabuzz Magmar Pinsir Tauros Magikarp Gyarados Lapras Ditto Eevee {Vapore,Jolte,Flare,Poryg}on Oma{nyte,star} Kabuto{,ps} Aerodactyl Snorlax Articuno Zapdos Moltres Dra{tini,gon{air,ite}} Mew{two,}|tr %\  \ \\n|sed $n!d
\$\endgroup\$
  • 3
    \$\begingroup\$ That is a really cool idea. \$\endgroup\$ – MrZander Nov 21 '12 at 18:32
17
\$\begingroup\$

PHP 919 (925) bytes

As with Peter Taylor's answer, I also cannot post my solution directly, so instead i'll post a program that generates it:

<?php
$data = <<<EOD
PD9mb3IoJG89J5SWUHYPaY6dSs/pjsJBMS1pRDc1yZ3AUcQkNcnZsYIkJDXtpa4UB4mOMNH8zbDbcDhcKD
VYu89cFyjRlBm8GSjMiFSxCNHitpn8Kdi43B+XUkX2gVjN8LQEmEkF5D2zE9gbTD3z6djUJQAVFXwlXV/o
kVwnsV1rW5J9zpssN3JXdW5LjAS3DYTcBtV/YUdtoAfGC+ztsoc1LxQamD5lmQMaes37flJcGvg7CdkS+s
1bhZLjAQQtmL5tS3rN+2eS7LeROnX9nOCRRWhRQhFkBDSN0igwMUwem4BNYVrkxZuAzUEiRDG+KFODVqV0
KDAvpLM747wC0AwYUVkELsVsBA5vyThUQQtiKFRBK6EYnBC7oMiAkJtYbXOZk9scdPF3hTJEh7hhZ4yDEG
FHzJ1vSfxkDVkd8fz+u6ConHVH7Y3SHFtgq20M22ALpO40xMC9vmictX6lf+2VfqV1EBctRRwZ38RceT3E
G2l5PcTVTFahWEdGGYhjKSwy5lBYAn944VmhWNQRkvXDw5SAkpV/URm0SZPBOPweZUGwDlODERHEwt0VfK
X9WG+kp9tbe+d8oLvu1uw9+6ExyFwZe6LogoTF7oG3RCiUm0GTcJsmcyxJmdRR68Oi7P4NmQ6ZlwxE8djR
DtfANTjRZBOvWE281RLRDtPJY05E4k10BkvfCRwNLKssXh4GHB+SgBFEwsDbHsSxMdhmCBExsfvZKLzEEY
uZ26SXfutBOR1rezc8/XmT6HkcHciTBwTSxD1cJ+XBcmyjis2S7ClZLZJMTG2bngTs7VtCN3VSaQUAcuPQ
VR9yY0+ntSTcnhcdZ4n4JtzDwPHZJEl9pZJsONV96ad1jpV5eVhpldF8r7WcMeRd8hSxMXjVEcZEPZsdLg
SSd+4kNY7L7Bkbdy10VDVuJdtfGOyG7yydwJux2SFcAiz7QSIEa8BxAoQIFUFCRJt+G6KkoZ3d8fzBPZhO
xG2eaIwfvrGb54zZ7mgfGPA0Qp6I5NSund9SSw5MUD8M0wAmzywmSF2N/CZbw8V1JEZF42LIXJmLeIM5uU
wnOzc4OD4kbjspJGY9c3BsaXQonywkeC49Y2hyKDMxJiR2PSsrJGklOCUzPzgqJHZeb3JkKCRvWyRuKytd
KTokdj4+NSleiyk7ZWNob35zdHJ0cigkZlsrZmdldHMoU1RESU4pXXygLICEgYOCLNfY1tHfKTsNCg==
EOD;
print base64_decode($data);
?>

Sample I/O:

$ php generator.php > out.php

$ echo 12 | php out.php
Butterfree

$ echo 32 | php out.php
Nidoran (m)

$ echo 83 | php out.php
Farfetch'd

$ echo 122 | php out.php
Mr. mime

$ echo 151 | php out.php
Mew

How it works (spoiler):

This code operates on the observation that there are only 32 unique characters, including a separator - if you're not counting capitals. This immediately implies a 5:8 encoding; only 5 bits are needed to represent each byte.

I accomplish this in the following manner:

++$i%8%3

When this value is non-zero, a new byte is read, and when zero, the next byte is generated from the previously read bytes. The 3rd, 6th, and 8th byte are generated in this manner, and then the process repeats.

The bit distribution follows accordingly. If for example you wanted to produce the string:

abcdefgh

The bits for each are distributed among the 5 source bytes in the following fashion:

hccaaaaa|cccbbbbb|hffddddd|fffeeeee|hhhggggg

After generating c, only the top most bit of h remains, after generating f, the top two bits of h remain, and after reading g, h remains in its entirety (I save a few shift operations by using xored values instead, for example the value I load for the second byte is the value I want xor a<<3, but that's the gist of it).

This produces characters on the range of [0,31]. By xoring by any character on the range [96,127], all characters will be mapped to that range (I chose 116, because it resulted in the least amount of escape sequences). After that, it's a simple matter of translating the 5 characters that don't belong there with their appropriate replacements, and capitalizing the first letter. This code requires three bytes to do so: oring the (previously generated as such) bit inverted string with char 160, and then bit inverting back. A small caveat: the second m in 'Mr. mime' is not capitalized by this method. This could be repaired by replacing the method described above with the ucwords() function, at the cost of 6 bytes, resulting in a code length of 925, instead of 919.

\$\endgroup\$
7
\$\begingroup\$

GolfScript (1040 bytes)

Unfortunately I can't directly post the program, so I'll provide a link and the base64-encoded text:

fignACc1Nix7XFsxJF0nJysvXCdCdWxiNzYKSXZ5czY0dXM2CjJtMWQvMm0tZSsyaXozZCpxdSZ0
bCVXMyRydGwlQmw3JGlzJUMjMHBpImUhcB8KQnV0dDBmcmUlHmRsJUtha3VuYQpCZWVkHWxsG3kb
b3QkG290GiN0I2EaI2ljIyVTcGUzGQpGZTMZCkVrMXMYcmJvaxxpa2EXdRphaRd1KjFkc2hyZXcq
MWRzbDdoFWYpFnIUYRZxdWU1FW0pFnIUbxZrExEmeRFibCVWdWxwaXgKThRlIRJzCkoQcHVmZgpX
EHR1ZmYKWnViIw8OYiMKT2RkaXNoD2xvb20KVmkScGx1bSVQMzccMzdlY3Q0LCM0b21vdGgNaWcS
dHQNdWd0HW8MZRl0aBwwc2kxHHN5ZHVjaw8OZHVjawwxa2V5HB1tZQslR3IZbAloGHJjMRQlUAhh
ZxwIaCZsHAgHdGgYYgcGYWRhYgcYbGFrYXphbQUXb3AFF29rImEXYW1wCkItbHNwcm91dAoecBRi
LWwKVmljdHJlZWItbARvDgRydS0PZR91ZCVHB3YtL0cOZW0cLHkhGgtpZDdoKmwZcG9rJVNsGWJy
bwVnbmVtCSJhZ25ldCtGM2ZldBdcJ2QNH3VvDR8dbyplLQ1ld2csZw8dbS9NdWsqaC1sZC9DbG95
c3QvRzd0bHkKSGF1bnQvRzVnMwpPbml4DXIZc2UlSHlwbm8GB2JieQYTbC9WDiRyYgpFEmN0ch8D
dAMkcgpDdWIsIjMZYWsKSAltLBIlSAltLBcxCkxpY2sJdW5nBm9mZhMKHnoTGmh5aAJuGmh5ZCtD
aDFzZXkKVDFnLWEGMWc3a2gxCkgCc2VhKmVhZAcPDmRlNSplYWsTKnQzeXUqdDNtaSJyLiBNaW0l
U2N5dGgvSnlueApFEmMhYnV6egVnbTMcFHMmClQ2b3MFZ2lrM3APeTNhZG9zCkwLB3MNCSQKRWV2
ZSVWCwJlK0oOdGUrRmwzZSwcAnlnK09tMXl0JU9tN3QzAQFwcxgwH2FjdHlsKm4CbGF4GHJ0aWN1
bm8KWgtkb3MMDnRyZXMNB3QUaQ0HZyxhJg0HZywJImV3dHdvDGV3AAZhYnUkAG9yACVFeGVnZ3UA
ClQ1IWMADGEACksAcmEADml3AGl0AAoAYXAACk0ACkQAb2wACkcAaWdnbHkACkMSZmEAbGUAFGcA
aW4AFnIxICgACk5pZG8AY2gACkEAb3cAClIAHGlkZ2UAClAAcmkAV2VlAG9kACAAdGEAJU0AYXQA
dG8AZQoAaXIAXCcAKAApAApTACwKAG9uAGVsAC4AMAoAZXIAYW4AQ2gzAGFyAApWNQBlbgBhdXIA
YXMnJwAnLz0qfS9uLz0=

It uses a grammar-based approach with rules separated by NUL characters and a simple expansion approach, followed by splitting on newlines and selecting the desired line. Input is via stdin. No external file is used.

In more detail

I have written a Java program which applies several grammar-generating strategies and two grammar-to-GolfScript generation strategies and outputs a lot of GS programs to reconstruct a string. In this particular case the winning combination was a greedy grammar builder with a threshold of 2, and the remap engine. The greedy grammar builder starts with a grammar

<0> ::= "Bulbasaur\nIvysaur\nVenusaur\n..."

and repeatedly looks for the repeated sequence of terminals and non-terminals in the right hand sides which, when pulled out into a rule defining a new non-terminal, produces the greatest decrease in the total number of terminals and non-terminals in the grammar. The threshold is the cutoff point at which the decrease is considered no longer worth it.

The non-terminals are topologically sorted and then numbered from 0 up. If they overlap any character values which are also terminals, the remap engine creates a new rule mapping to that terminal. (E.g. if there are rules 0 to 37 and the space character occurs, it will map 38 to the space character and then update the RHS of all rules to use 38 instead of 32). The right hand sides of the rules are then concatenated, separated by NULs, and a small piece of hand-written GolfScript to expand the grammar is appended.

\$\endgroup\$
  • 2
    \$\begingroup\$ +1 Would you say a bit more about your approach? \$\endgroup\$ – DavidC Nov 21 '12 at 23:55
3
\$\begingroup\$

brainfuck, 9337 bytes

Pretty sure I will find a shorter solution ^^

--->->>>>->>->>>-->->>>>->>>-->->>>>>->>>-->->>->>>->>>>>-->->>->>>>>>>>-->->>->>>>->>>-->->>>>>>>>-->->->>>>>>>>-->->>->>>>>>>-->->->>>>>>>-->->>>->>>>-->->>>>>>>>>>-->->>>>>>-->->->>>>->-->->>>>>>>>-->->>>>>>-->->>>>>>>>>-->->>>>>>>-->->->>>->>->-->->->>>>->>>-->->>>->>>>-->->>->>>>-->->>->>>-->->>>>>-->->>>->>>>-->->->>>>>-->->->>>>>>>>-->->->>>>>->>>-->->>>>>->>-->-->>-->-->->>>>>>>->-->->>>>>>>>>-->->>>>>->>-->-->>-->-->->>>>>>>>-->->>>>>>>>-->->>>>->>>>-->->>>>->>>>-->->>>>>>-->->>>>>->>>>-->->>>>>>>>>>-->->>>>>>>>>>-->->>>->>-->->>>>->>-->->>>>>>-->->>>>>-->->>>>>>>>>-->->->>->>-->->->>->>>>>-->->>>>>->>-->->>>>>>>>-->->>>>>>>-->->>>>>>>-->->>>>>>-->->>>>>->>-->->>>>>>>-->->>>>>>>-->->->>>>>-->->>>>>->>>-->->>>>>>>>-->->>>->>>>>-->->>>>>->>-->->>>>>>>>>-->->>>>>>->>>-->->>>->-->->->>->>>->-->->>->>->>->>-->->->>>>>-->->->>>>>>-->->->>>->>>-->->>>>>>>>>>-->->>>>>>>>>>-->->>>>>>>>>>>-->->>>>->>>>>-->->>>>->>>>>>-->->>>>>>>-->->>->>>>>>-->->>>>>-->->>>>>->-->->->>>>->>>-->->>>>>>>>-->->>>>>>>-->->->>>>>>>>-->->->>>>>>>-->->->>>>>>>-->>-->->>>>>-->->>>>>>-->->>>>-->->>>>>>>-->->>>>>>-->->>>-->->>>>>>>>-->->>>>>>>>-->->->>>>>-->->->>>>>>-->->>>>->>-->->>>>-->->>>>>>>-->->>>>>-->->>->>>>-->->>>>>>>-->->>>>>>>-->->>>>>>>>>-->->>>>>>>>-->->>>>>>>>>-->->>>>>>-->->->>>>->>-->->>>>>>>>>-->->>>>>>>>->>-->->>>>>>>>>-->->>>>>>>-->->>>>>>>-->->>>>>>>-->->>>>>>-->->>->>>>>-->->->>>>>->-->->->>>->>>>->>-->->>>>>->-->->>->>>->-->->>>>>>>-->->>->>>>>-->->>->>>>-->->>->>>>>-->->>-->-->->>>>-->->>>>>>>-->->>>>-->->>>>>->>>>>-->->->>>->>-->->>>>>>-->->->>>>>-->->->>>>->>>-->->>->>->>>>-->->->>>->>-->->>>>>-->->>>>>-->->->>>>>>>-->->>>>>>>-->->>->>>>>-->->>>>>>>-->->>->>>>>-->->>->>>->>-->->->>>>>-->->->>>>>>>-->->>>>>->>>>>-->->>>>>->>-->->>>>>>>>-->->->>>>>-->->>>>>>>-->->>->>>>>-->->>->>>>->>>-->->>->>>>>>>-->->>>>>>-->->>>+[-[>+++++++<-]<+++]>---->->->-->--->+++>->+++>->->--->>->>->+++>->->--->++>--->-->->->+++>->->--->->--->+++>->-->+++>-->--->--->->--->->--->+++>->-->--->-->--->-->-->--->->--->+++>->-->>+++>->--->--->+>->->-->->->-->--->--->++>+++>->->-->->->-->--->--->->-->+++>->->-->-->->--->--->->+++>->--->->->-->--->--->+>--->->+++>->-->--->--->->->->->--->->--->->--->--->--->++>--->--->--->-->--->--->>+++>-->->-->+++>--->->--->--->--->->-->-->-->--->+>-->--->--->--->>--->+>-->--->--->--->-->->->-->--->+>-->--->--->--->-->->--->+>+++>->->+++>->+++>--->+>+++>->-->--->+++>->--->--->+>->--->+++>->-->>--->>--->+++>->-->>--->->-->+++>-->->--->->->--->-->-->--->+>-->-->+++>--->--->->--->+>+++>-->--->--->->--->+>+++>-->--->->--->->--->>--->+>+++>-->--->->-->+++>->--->--->+>-->--->-->->+++>-->+>++>--->++>--->+>-->--->-->->-->-->+++>--->+>-->--->-->->->--->--->-->--->+>-->--->-->->+++>-->+>++>-->++>--->+>-->--->-->->-->-->-->--->+>-->--->-->-->-->-->--->--->->-->--->--->+++>-->->>--->->-->--->--->+++>--->-->--->--->++>->-->->-->>--->+>-->-->--->->+++>-->--->->--->>-->--->--->-->>->->--->--->--->++>-->--->--->-->>->->--->--->--->++>->--->+++>->--->>-->-->--->+++>->--->+>--->--->-->->--->--->>-->-->-->-->--->++>-->-->--->->-->->-->--->--->+>+++>->+++>->--->+>+++>->+++>->--->--->->--->++>--->-->-->-->+++>->--->++>--->-->-->-->-->->--->--->->-->--->-->--->->->--->->->--->->->-->-->--->+>--->-->>->--->--->+>--->->->-->+++>-->--->+>->>--->->--->-->--->>-->-->--->->--->-->--->+>+++>-->-->--->>--->+>->-->-->--->+++>->--->--->>->-->>-->-->->--->--->->->--->+++>-->-->-->--->--->+>-->-->-->>+++>--->--->+>-->-->-->>--->-->->-->--->+>-->-->-->>->+++>->--->--->->--->->+++>--->>+++>--->+++>--->->+++>--->->-->+++>-->+++>>+++>-->--->+>+++>--->--->-->->--->+>+++>--->--->-->-->--->--->+>+++>--->--->+++>-->->--->->--->-->-->->->->-->->->--->++>--->--->->-->-->--->--->-->-->--->++>-->--->->->--->--->--->--->-->-->--->++>--->-->->+++>--->-->-->-->--->++>--->-->->+++>--->->->--->-->--->>--->-->--->->--->--->--->>->+++>->--->-->--->->--->>-->-->--->-->--->+>-->-->>->+++>--->+>+++>->-->--->+++>->--->--->+>-->-->>->-->-->--->--->+>-->-->>--->->-->--->+>+++>--->-->--->-->-->->--->--->+>+++>--->-->--->->-->-->--->>+++>->--->--->->--->--->++>--->--->->-->--->->-->--->->-->--->->-->-->--->+>--->--->-->--->->--->>--->-->-->--->--->>->-->-->--->->--->+>->-->--->+>--->--->-->-->--->--->->--->->-->-->>->->--->->--->>+++>->->-->>--->>+++>->-->->--->->--->>--->-->--->+++>->--->+>-->-->>--->->->-->>->--->--->--->>>->-->-->--->>->+++>--->--->>--->>-->-->--->-->--->->--->++>-->-->->-->->--->--->->-->--->--->->->-->--->--->--->->>--->--->--->->->--->--->->>--->--->--->->->-->->--->->->--->-->-->--->--->+>+++>->-->>+++>-->--->>-->->-->-->-->-->--->--->--->>-->->-->-->-->--->--->+++>-->--->>-->--->-->-->->->-->--->--->>-->--->--->-->-->--->--->++>--->--->>-->-->--->--->+>--->>--->-->->-->--->+>--->>--->-->-->--->->--->+++>-->->--->>--->++>+++>-->--->--->-->+++>--->>+++>-->--->+++>->-->--->+++>-->--->>-->->->--->+++>--->+>--->+++>--->->+++>--->>-->-->--->--->--->-->--->+>--->+++>-->-->-->--->--->+>->+++>->>->--->+>->+++>->-->-->--->--->+>->+++>+>+>-->-->--->--->+>--->>->--->--->->--->>>-->>--->->-->--->--->->+++>--->->>>--->+>+++>--->-->+++>->--->+>-->-->->-->->--->++>+++>->->-->->--->+>+++>--->-->-->+++>->->--->>>+++>->+++>--->-->->--->>+++>->->+++>->--->->-->->->-->--->->--->->--->--->--->++>+++>->-->->--->-->-->--->>-->-->->--->-->-->--->>-->+++>->--->-->-->--->+>-->->>--->-->-->--->+>-->+++>-->>->--->--->+>-->+++>->->+++>->--->>+++>--->->->-->--->>+++>--->->->-->->->--->->--->->-->--->+++>--->->>-->--->+>-->-->->-->+++>>--->->->->-->--->->-->-->--->++>+++>->--->-->->--->+>-->-->->->--->->--->->->+++>->-->-->-->--->->->+++>--->-->-->+++>-->->--->->->+++>--->-->-->-->->--->--->+>--->>->>-->--->+>--->>+[-[>+++++++<-]<++++]>---->>++>>--->+++>>+++>++>->--->>+++>->>+++>++>->--->->>++>++>>+++>++>->--->+>+++>+++>->+>+++>++>->>->--->+>+++>+++>->+>>>>+++>++>--->+>+++>+++>->--->>+++>->->--->+++>-->++>--->->+>>>--->>+++>->+>+++>->+>>>--->>>+++>>+>+++>--->>>--->+>+++>+>>->--->--->>--->--->>+>+++>--->+++>->--->>++>+>+>>->+>->>>--->>>>->>>--->++>+++>->++>++>+++>--->>>>->->--->>>--->>--->->++>>->--->>--->->++>>+++>+>+>+++>--->>--->->++>>+++>+>--->++>+++>+>+>+++>+>+++>--->++>+++>+>--->-->+++>+>>--->+++>--->>+++>->+++>--->--->--->>+++>->+++>--->--->+++>->+++>++>>--->->->--->+++>->--->>--->->+++>-->+++>++>--->++>+++>--->-->+++>++>--->+++>+++>++>->>+++>->>--->--->+++>+++>++>->>>+++>>+++>--->-->--->->+++>->+++>++>+>++>+>+++>--->-->--->->+++>->--->++>+++>--->-->--->->+++>-->++>>>++>--->-->--->->+++>->+++>++>+>++>+>+++>--->-->--->->+++>->--->++>+++>--->-->--->->+++>->--->++>++>--->+>>>+>+++>--->->->--->+>>>+>+++>--->>>--->->++>>--->--->-->--->-->--->++>>+>+++>>>>--->+>--->++>++>>->--->++>+>+>--->>--->++>++>>->+>++>+>+>--->+++>++>--->+++>+>--->-->+++>>--->+++>+>--->->->->--->>+++>--->-->>+++>+++>+>--->->--->>>--->>++>+>>--->>+++>->+++>>--->>+++>->+++>>>-->+>--->->>++>+++>++>+++>+>--->->>++>+++>+>+++>+>+++>--->++>--->++>>>+>+>--->++>++>++>+>->--->+++>--->--->>+++>--->+>+++>--->>>->>--->+++>++>--->>>->->++>-->->--->-->+++>>->++>-->->--->--->+++>++>->>->--->>->--->+>>+++>--->>--->-->->+++>--->>--->+>+++>--->->->-->+++>++>--->++>>--->>+++>>--->--->+++>++>--->>+++>>--->--->+++>--->->>--->>+++>>--->--->->+++>+>+++>--->->--->->+++>--->++>+++>->+++>--->->+++>--->->>+++>->+++>>+++>+>--->--->+++>-->+++>+++>--->--->--->+++>-->+++>+++>->>--->--->+++>-->+++>+++>+>--->--->>>>>>--->->+++>++>+>--->>>>--->--->++>--->>>>--->->--->-->+>->>>--->>>>--->--->>++>+>+++>-->+++>+++>>--->--->>++>+>+++>-->->++>>>--->-->>+++>->++>->>--->-->->+++>+++>>>>->--->-->+++>>>+>--->>+++>++>->+>+++>--->++>+++>--->--->->+++>>+++>--->+++>>+++>--->--->+++>->>--->+++>>+++>--->--->->+++>--->--->+++>++>++>>+>--->+>>--->--->+++>++>++>>+>+++>++>--->--->+++>->+>>+>-->+++>+>->--->++>+++>->++>+++>--->++>+++>->->--->+++>--->+++>>>>--->++>>--->++>+++>++>++>--->-->->--->+>>->--->--->++>->--->+++>+++>>>>->>->--->+>>+++>->>+>>->--->-->+++>>+>>->--->->+++>++>++>+>>->--->-->>++>++>+++>->--->->++>--->-->--->++>->+++>--->>>>--->->->--->++>+++>--->++>->+++>--->--->->--->++>--->++>++>>>->--->->+++>>+>+++>->--->--->+++>>>-->+>->+++>->>--->+++>-->>++>++>++>+>>--->+++>-->>++>++>++>+>+++>->--->+>++>--->+++>++>>--->--->+++>->+++>--->+++>->--->->--->+>+>+++>++>>>>--->->--->+>+>+++>++>-->+++>+++>++>--->+++>--->-->->--->+>++>++>++>--->++>+++>+>+>--->++>++>--->>>>>--->++>++>--->++>+++>->+++>+++>->++>--->++>+++>->->+++>++>--->+>+++>+++>++>>>->--->--->+++>++>++>>>+++>--->++>+++>++>++>+++>>->+++>+++>++>--->->+++>->>>+++>--->+++>>+++>->->+++>--->-->+++>>->>>++>--->+++>>+++>->--->++>++>--->+++>+>+++>->->++>--->+++>+>+++>->+>--->>--->--->->+>+>--->--->+>>--->+++>-->->+>+++>>->--->+>->++>-->--->+++>>>-->+>+++>--->++>>>--->--->+++>++>+>+++>->--->>--->++>>--->->--->--->+++>++>->+++>>--->--->+++>++>--->->+++>->--->--->-->->+++>->+++>->+++>>--->+++>+++>--->->+++>>--->++>--->+>+>+++>--->+++>>+++>>>--->->+++>--->+++>->>+++>++>--->+>+++>>+>>+++>++>--->--->>+++>->>+++>++>--->>+++>->->++>+++>++>--->->+>+++>++>->+>>--->->+>+++>>+>+++>->--->++>+++>--->++>+>+++>--->++>+++>--->++>+>+++>--->>--->->>->+++>->+++>-->+>->>--->+++>++>+++>->>+++>-->--->->->+>--->-->++>++>+++>--->+++>+++>--->->+++>>--->--->+++>>+>->>>--->++>->+++>+>--->++>--->--->++>->+++>++>+++>++>+++>--->->--->++>->+++>++>+++>++>--->+>>--->--->>--->+>--->+++>--->--->>--->+[-<++++]<<<,[>[>+<-]>[<++++++++++>-]<<<++++++++[>------<-]>[>+<-],]>-[>>[>]+[<]<-]>>[>]>[.>]

Try it online!

\$\endgroup\$
2
\$\begingroup\$

q/kdb, 789+77 = 866 bytes

Solution:

/ encoding pokemon.txt into 'q' text file (not added to byte count, not golfed)
`:q 0:enlist "c"$2 sv'8 cut (raze 3_'0b vs'4h$(asc distinct p)?p:lower first read0`:pokemon.txt),000000b

/ checking length of q file (note: file is written with trailing newline \r\n, so could/should be 787 bytes)
hcount `:q
789

/ decoding q and look-up of value
@[;0;upper](";"vs(" '().;",.Q.a)2 sv'5 cut -6_(,/)0b vs'4h$"\n"sv(0:)`:q)@-1+

Examples:

q)@[;0;upper](";"vs(" '().;",.Q.a)2 sv'5 cut -6_(,/)0b vs'4h$"\n"sv(0:)`:q)@-1+45
"Vileplume"
q)@[;0;upper](";"vs(" '().;",.Q.a)2 sv'5 cut -6_(,/)0b vs'4h$"\n"sv(0:)`:q)@-1+151
"Mew"
q)@[;0;upper](";"vs(" '().;",.Q.a)2 sv'5 cut -6_(,/)0b vs'4h$"\n"sv(0:)`:q)@-1+1
"Bulbasaur"

Explanation:

The strategy (like other solutions) is to encode each 8 bit character in 5 bits, this is done by creating a smaller alphabet of 32 characters, finding the indices of each letter in the input list (0..31) and then encoding these as 5-bit numbers (which need to be joined and converted to 8-bit chars to be written down in Q).

The decoding is just doing the opposite of this, the alphabet is known to be " '().;abcdefghijklmnopqrstuvwxyz", so split the input into batches of 5 bits and convert back into integers, index into the alphabet. Split this on ; and then index into it with user input (subtract 1 due to 0-indexing), and (re)capitalise the first letter.

@[;0;upper] (";" vs " '().;abcdefghijklmnopqrstuvwxyz"2 sv'5 cut -6_raze 0b vs'4h$ "\n" sv read0 `:q)@-1+ / ungolfed decoder
                                                                                                      -1+ / same as doing 'x-1', subtract 1 from input
                                                                                                     @    / index in to item on the left
            (                                                                                       )     / do all this together
                                                                                           read0 `:q      / read text file 'q'
                                                                                   "\n" sv                / join back newlines (as q breaks text files on newlines)
                                                                               4h$                        / cast char array to bytes
                                                                         0b vs'                           / convert each byte to binary (boolean list)
                                                                    raze                                  / flatten list
                                                                 -6_                                      / drop the 6 padding bits added to align 5/8-bits
                                                           5 cut                                          / chop into lists of 5-bit lengths
                                                      2 sv'                                               / convert each boolean list back to an integer
                    " '().;abcdefghijklmnopqrstuvwxyz"                                                    / index into our lookup table at each index
             ";" vs                                                                                       / break this string up at semicolons
 @[;0;upper]                                                                                              / apply 'upper' to each first character in the result

Notes:

An extra 13 bytes (879) if we need to capitalise the second M of Mr. Mime:

{@[x;0,1+x ss" ";upper]}(";"vs(" '().;",.Q.a)2 sv'5 cut -6_(,/)0b vs'4h$"\n"sv(0:)`:q)@-1+
\$\endgroup\$
2
\$\begingroup\$

Python 3, 178+1253=1431 bytes

import re
def f(l,N,p='',n=0,w=''):
 for s in open(l,'r',1,'utf-8').read().split('\0'):t=re.match('\d*',s)[0];n=int(t or n);w=w[:n]+s[len(t):];p+=w[:-1]*(ord(w[-1])==N)
 return p

Credit to wizzwizz4 for their Bookworm decompression function: Parse the Bookworm dictionary format

Must pass the filename and the desired Pokemon number to the function. Returns a string containing the Pokemon.

Ex.: f('pokemans', 1') returns 'Bulbasaur'.

The file uses BookWorm compression, but since the Pokemon must be in alphabetical order for this to work, they all end with a character whose ordinal matches their number (Ex. Nidorino appears as "7o!", "7o" being the compressed string "Nidorino" and "!" being \33). Items are delineated by the null byte \0, since Pokemon chars start at \1.

Due to the complexity of decompressing BookWorm, this is actually worse than taking the basic hard-coded list, then splitting and indexing it. But it's a novel answer, so I thought I'd post it anyway.

Hex dump of 'pokemans' file:

41 62 72 61 3f 00 31 65 72 6f 64 61 63 74 79 6c c2 8e 00 6c 61 6b 61 7a 61 6d 41 00 72 62 6f 6b 18 00 32 63 61 6e 69 6e 65 3b 00 74 69 63 75 6e 6f c2 90 00 30 42 65 65 64 72 69 6c 6c 0f 00 32 6c 6c 73 70 72 6f 75 74 45 00 31 6c 61 73 74 6f 69 73 65 09 00 75 6c 62 61 73 61 75 72 01 00 32 74 74 65 72 66 72 65 65 0c 00 30 43 61 74 65 72 70 69 65 0a 00 31 68 61 6e 73 65 79 71 00 33 72 69 7a 61 72 64 06 00 34 6d 61 6e 64 65 72 04 00 35 65 6c 65 6f 6e 05 00 31 6c 65 66 61 62 6c 65 24 00 35 69 72 79 23 00 32 6f 79 73 74 65 72 5b 00 31 75 62 6f 6e 65 68 00 30 44 65 77 67 6f 6e 67 57 00 44 69 67 6c 65 74 74 32 00 32 74 74 6f c2 84 00 30 44 6f 64 72 69 6f 55 00 33 75 6f 54 00 31 72 61 67 6f 6e 61 69 72 c2 94 00 36 69 74 65 c2 95 00 33 74 69 6e 69 c2 93 00 32 6f 77 73 65 65 60 00 31 75 67 74 72 69 6f 33 00 30 45 65 76 65 65 c2 85 00 31 6b 61 6e 73 17 00 6c 65 63 74 61 62 75 7a 7a 7d 00 35 72 6f 64 65 65 00 31 78 65 67 67 75 74 65 66 00 37 6f 72 67 00 30 46 61 72 66 65 74 63 68 27 64 53 00 31 65 61 72 6f 77 16 00 6c 61 72 65 6f 6e c2 88 00 30 47 61 73 74 6c 79 5c 00 31 65 6e 67 61 72 5e 00 32 6f 64 75 64 65 4a 00 31 6c 6f 6f 6d 2c 00 6f 6c 62 61 74 2a 00 33 64 65 65 6e 76 00 34 75 63 6b 37 00 33 65 6d 4c 00 31 72 61 76 65 6c 65 72 4b 00 32 69 6d 65 72 58 00 32 6f 77 6c 69 74 68 3a 00 31 79 61 72 61 64 6f 73 c2 82 00 30 48 61 75 6e 74 65 72 5d 00 31 69 74 6d 6f 6e 63 68 61 6e 6b 00 36 6c 65 65 6a 00 31 6f 72 73 65 61 74 00 79 70 6e 6f 61 00 30 49 76 79 73 61 75 72 02 00 4a 69 67 67 6c 79 70 75 66 66 27 00 31 6f 6c 74 65 6f 6e c2 87 00 79 6e 78 7c 00 30 4b 61 62 75 74 6f c2 8c 00 36 70 73 c2 8d 00 32 64 61 62 72 61 40 00 32 6b 75 6e 61 0e 00 32 6e 67 61 73 6b 68 61 6e 73 00 31 69 6e 67 6c 65 72 63 00 6f 66 66 69 6e 67 6d 00 72 61 62 62 79 62 00 30 4c 61 70 72 61 73 c2 83 00 4c 69 63 6b 69 74 75 6e 67 6c 00 4d 61 63 68 61 6d 70 44 00 34 6f 6b 65 43 00 35 70 42 00 32 67 69 6b 61 72 70 c2 81 00 33 6d 61 72 7e 00 6e 65 6d 69 74 65 51 00 35 74 6f 6e 52 00 32 6e 6b 65 79 38 00 72 6f 77 61 6b 69 00 31 65 6f 77 74 68 34 00 32 74 61 70 6f 64 0b 00 77 c2 97 00 33 74 77 6f c2 96 00 31 6f 6c 74 72 65 73 c2 92 00 72 2e 20 4d 69 6d 65 7a 00 75 6b 59 00 30 4e 69 64 6f 6b 69 6e 67 22 00 34 71 75 65 65 6e 1f 00 72 61 6e 20 28 66 29 1d 00 39 6d 29 20 00 35 69 6e 61 1e 00 37 6f 21 00 32 6e 65 74 61 6c 65 73 26 00 30 4f 64 64 69 73 68 2b 00 31 6d 61 6e 79 74 65 c2 8a 00 33 73 74 61 72 c2 8b 00 31 6e 69 78 5f 00 30 50 61 72 61 73 2e 00 35 65 63 74 2f 00 31 65 72 73 69 61 6e 35 00 69 64 67 65 6f 74 12 00 35 6f 74 74 6f 11 00 79 10 00 32 6b 61 63 68 75 19 00 6e 73 69 72 7f 00 31 6f 6c 69 77 61 67 3c 00 35 68 69 72 6c 3d 00 72 61 74 68 3e 00 32 6e 79 74 61 4d 00 72 79 67 6f 6e c2 89 00 31 72 69 6d 65 61 70 65 39 00 73 79 64 75 63 6b 36 00 30 52 61 69 63 68 75 1a 00 32 70 69 64 61 73 68 4e 00 74 69 63 61 74 65 14 00 33 74 61 74 61 13 00 31 68 79 64 6f 6e 70 00 33 68 6f 72 6e 6f 00 30 53 61 6e 64 73 68 72 65 77 1b 00 35 6c 61 73 68 1c 00 31 63 79 74 68 65 72 7b 00 65 61 64 72 61 75 00 33 6b 69 6e 67 77 00 32 65 6c 56 00 31 68 65 6c 6c 64 65 72 5a 00 6c 6f 77 62 72 6f 50 00 34 70 6f 6b 65 4f 00 31 6e 6f 72 6c 61 78 c2 8f 00 70 65 61 72 6f 77 15 00 71 75 69 72 74 6c 65 07 00 74 61 72 6d 69 65 79 00 34 79 75 78 00 30 54 61 6e 67 65 6c 61 72 00 32 75 72 6f 73 c2 80 00 31 65 6e 74 61 63 6f 6f 6c 48 00 36 72 75 65 6c 49 00 30 56 61 70 6f 72 65 6f 6e c2 86 00 31 65 6e 6f 6d 6f 74 68 31 00 34 6e 61 74 30 00 33 75 73 61 75 72 03 00 31 69 63 74 72 65 65 62 65 6c 6c 47 00 32 6c 65 70 6c 75 6d 65 2d 00 31 6f 6c 74 6f 72 62 64 00 75 6c 70 69 78 25 00 30 57 61 72 74 6f 72 74 6c 65 08 00 31 65 65 64 6c 65 0d 00 33 70 69 6e 62 65 6c 6c 46 00 7a 69 6e 67 6e 00 31 69 67 67 6c 79 74 75 66 66 28 00 30 5a 61 70 64 6f 73 c2 91 00 31 75 62 61 74 29 00

\$\endgroup\$
  • 1
    \$\begingroup\$ 1286 Bytes when using a simple string instead of a file (Try it online)[bit.ly/2O0pZK0]. But the idea of the file compression is nice. \$\endgroup\$ – pixma140 Jul 18 at 11:09
1
\$\begingroup\$

Pure Bash (no coreutils), 1173 bytes

read n;set {Bulba,Ivy,Venu}saur Char{mander,meleon,izard} {Squi,Warto}rtle Blastoise Caterpie Metapod Butterfree Weedle Kakuna Beedrill Pidge{y,otto,ot} Rat{tata,icate} {Sp,F}earow Ekans Arbok {Pika,Rai}chu Sands{hrew,lash} Nido{ran\ \(f\),rina,queen,ran\ \(m\),rino,king} Clefa{iry,ble} Vulpix Ninetales {Jigglyp,Wigglyt}uff {Zu,Gol}bat Oddish Gloom Vileplume Paras{,ect} Veno{nat,moth} Diglett Dugtrio Meowth Persian {Psy,Gol}duck Mankey Primeape Growlith Arcanine Poliw{ag,hirl,rath} {A,Kada}bra Alakazam Mach{op,oke,amp} Bellsprout {Weepin,Victree}bell Tentac{ool,ruel} Geodude Graveler Golem Ponyta Rapidash Slow{poke,bro} Magne{mite,ton} Farfetch\'d Dod{uo,rio} Seel Dewgong Grimer Muk {Shelld,Cloyst}er Gastly Haunter Gengar Onix Drowsee Hypno Krabby Kingler Voltorb Electrode Exeggut{e,or} Cubone Marowak Hitmon{lee,chan} Lickitung {Koff,Weez}ing Rhy{horn,don} Chansey Tangela Kangaskhan Horsea Seadra Goldeen Seaking Star{yu,mie} Mr.\ Mime Scyther Jynx Electabuzz Magmar Pinsir Tauros Magikarp Gyarados Lapras Ditto Eevee {Vapore,Jolte,Flare,Poryg}on Oma{nyte,star} Kabuto{,ps} Aerodactyl Snorlax Articuno Zapdos Moltres Dra{tini,gon{air,ite}} Mew{two,};echo ${!n}

Try it online!

Uses brace expansion like this answer, but uses only bash builtins read, set, and echo. set sets the command line arguments to those given, so that, for instance, $1 is Bulbasaur. ${!n} is an indirect expansion, which expands into the variable of the variable with the name of $n.

\$\endgroup\$
1
\$\begingroup\$

JavaScript, 1277 1276 bytes

n=>";Bulbasaur;Ivysaur;Venusaur;Charmander;Charmeleon;Charizard;Squirtle;Wartortle;Blastoise;Caterpie;Metapod;Butterfree;Weedle;Kakuna;Beedrill;Pidgey;Pidgeotto;Pidgeot;Rattata;Raticate;Spearow;Fearow;Ekans;Arbok;Pikachu;Raichu;Sandshrew;Sandslash;Nidoran (f);Nidorina;Nidoqueen;Nidoran (m);Nidorino;Nidoking;Clefairy;Clefable;Vulpix;Ninetales;Jigglypuff;Wigglytuff;Zubat;Golbat;Oddish;Gloom;Vileplume;Paras;Parasect;Venonat;Venomoth;Diglett;Dugtrio;Meowth;Persian;Psyduck;Golduck;Mankey;Primeape;Growlith;Arcanine;Poliwag;Poliwhirl;Poliwrath;Abra;Kadabra;Alakazam;Machop;Machoke;Machamp;Bellsprout;Weepinbell;Victreebell;Tentacool;Tentacruel;Geodude;Graveler;Golem;Ponyta;Rapidash;Slowpoke;Slowbro;Magnemite;Magneton;Farfetch'd;Doduo;Dodrio;Seel;Dewgong;Grimer;Muk;Shellder;Cloyster;Gastly;Haunter;Gengar;Onix;Drowsee;Hypno;Krabby;Kingler;Voltorb;Electrode;Exeggute;Exeggutor;Cubone;Marowak;Hitmonlee;Hitmonchan;Lickitung;Koffing;Weezing;Rhyhorn;Rhydon;Chansey;Tangela;Kangaskhan;Horsea;Seadra;Goldeen;Seaking;Staryu;Starmie;Mr. Mime;Scyther;Jynx;Electabuzz;Magmar;Pinsir;Tauros;Magikarp;Gyarados;Lapras;Ditto;Eevee;Vaporeon;Jolteon;Flareon;Porygon;Omanyte;Omastar;Kabuto;Kabutops;Aerodactyl;Snorlax;Articuno;Zapdos;Moltres;Dratini;Dragonair;Dragonite;Mewtwo;Mew".split`;`[n]

Try it online! Node.Js because there's no plain JS

\$\endgroup\$
  • 1
    \$\begingroup\$ You can get rid of the brackets around the (n) and you can use .split`;` instead too to save 4 bytes \$\endgroup\$ – Expired Data Jul 12 at 9:34
  • \$\begingroup\$ @ExpiredData Thanks. \$\endgroup\$ – facepalm42 Jul 12 at 9:38
  • 2
    \$\begingroup\$ I think my phone is choking on the TIO URL, but you can save a byte by prefixing the string with ; and indexing from n, not n-1 \$\endgroup\$ – cole Jul 18 at 0:23
  • 1
    \$\begingroup\$ -83 Bytes, now: 1,193 Bytes - You can try it here - I just adapted @Chris Pure Bash variant with node.js brace expasion. \$\endgroup\$ – pixma140 Jul 18 at 8:05
  • 1
    \$\begingroup\$ @pixma140 Nah, I just think it's a cool thing. I might be able to shorten it someday, maybe? \$\endgroup\$ – facepalm42 Jul 18 at 10:49

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.