JavaScript (ES6), 915 ... 902 890 bytes
w=>[..."aZM?o@;LWu&P?D@zF@W: @aT&@nCEfvQ&R&Tb'b@&p@:Srn @ahlrdpdT'TRv:HUYG@&fSfYdG&SGHL@Mh@G@gs';@CS@km@OsirA@q@njOZS@O@';HYqHE&DJavq&&aYaBmZMf;bv@EqHg@Z@;dm@M@?@rs@d@@oDAosDT@d@ZeBVrq@jFooD@VV&&BvMEDKiuiPC@&@DYrD&eD@D@@:AwccKZiF:DKLXAwdL@w&@@u'Hc@@q&;D:::WjdN@N@xD&eFh@gh@&Md?&Ye@@&h@hNN'Z&qtKEd@@HtH&@'@&@xd&dZsv@oo@FDyd@@&&@&@HS'Hw?DF@@@MPfDfi'AH&@@pkZkuMyZhFNN'P?d@u@NN&B@uo'fdi@?ke&"].find((_,i)=>!(s-=`GD4~#_@'R<1*~7C7RbZ6F'"Sa&!*1),#''3'.+B6(K$.l%9&!#0@51""~/+!gaW!/.(5'-@0'';!%C.&""!-.$16.2>(#&g!!O,#8A50O!)*(9b|Z4@7V).;*A*HWO(g1$/*-4&SL1I#K$#"3"#=e/'V~4'B(*,.3),$@D3)*76-"\\&kL7(-4#=7!!#+(B/B!-%!"_+!")+)0$1:E84!L191&)(255)!3O<,90NN6&;Q2'"bO=*h7.%1![<o!%M'G5/R.0$-J*%\\~6T?>)16""L&!X94T4"3$!2'^070Y2a"##)#"&n&(+1*&!-M""73R5%'y0~$-6<".MV?+1*ED>!B6b!)%&)8.+$&X0~Q'E%8&#%S/H.1<#>~!sU`.charCodeAt(i)-32),w=w.replace(/\W/g,1),s=parseInt((w+=w+w)[0]+w[2]+w[3]+w[6]+[...w].pop(),36)%8713)
Formatted
Below is a formatted version of the code with truncated payload data.
w => [..."aZM(…)"].find(
(_, i) =>
!(s -= `GD4(…)`.charCodeAt(i) - 32),
w = w.replace(/\W/g, 1),
s = parseInt((w += w + w)[0] + w[2] + w[3] + w[6] + [...w].pop(), 36) % 8713
)
How it works
Step #1
We first reduce the monster name by:
- Replacing non-alphanumerical characters (spaces and dashes) with
1
's. - Repeating this string 3 times to make sure that we have enough characters to work with for the next step.
- Keeping only the 1st, 3rd, 4th, 7th and last characters.
Examples:
1.34..7..L
Demogorgon -> Dmorn
^ ^^ ^ ^
1.34..7.L
orc mummy -> orc1mummy -> oc1my
^ ^^ ^ ^
1.34..7....L
xorn -> xornxornxorn -> xrnrn
^ ^^ ^ ^
This leads to a few collisions. For instance, "Master Assassin"
and "Master Kaen"
are both reduced to "Mst1n"
. Fortunately, all colliding monster names share the same symbol (@
in this case).
Step #2
Then, we interpret this 5-character string as a base 36 quantity to convert it to decimal (this operation is case insensitive) and we apply a modulo 8713
, which was empirically chosen to produce a collision-free list of keys.
Examples:
Dmorn --[from base 36]--> 22893539 --[MOD 8713]--> 4488
oc1my --[from base 36]--> 40872778 --[MOD 8713]--> 95
xrnrn --[from base 36]--> 56717843 --[MOD 8713]--> 4926
Step #3
All keys are sorted in ascending order:
[ 39, 75, 95, 192, 255, 287, 294, 344, 372, 389, 399, 516, 551, 574, 624, ..., 8635, 8688 ]
Converted to delta values:
[ 39, 36, 20, 97, 63, 32, 7, 50, 28, 17, 10, 117, 35, 23, 50, ..., 83, 53 ]
And encoded as ASCII characters in the range [ 32, 126 ]
. Some intermediate dummy values are inserted when the difference between two consecutive keys exceeds the maximum encodable magnitude.
Finally, the list of keys is mapped to a list of symbols arranged in the same order.
Test
f=
w=>[..."aZM?o@;LWu&P?D@zF@W: @aT&@nCEfvQ&R&Tb'b@&p@:Srn @ahlrdpdT'TRv:HUYG@&fSfYdG&SGHL@Mh@G@gs';@CS@km@OsirA@q@njOZS@O@';HYqHE&DJavq&&aYaBmZMf;bv@EqHg@Z@;dm@M@?@rs@d@@oDAosDT@d@ZeBVrq@jFooD@VV&&BvMEDKiuiPC@&@DYrD&eD@D@@:AwccKZiF:DKLXAwdL@w&@@u'Hc@@q&;D:::WjdN@N@xD&eFh@gh@&Md?&Ye@@&h@hNN'Z&qtKEd@@HtH&@'@&@xd&dZsv@oo@FDyd@@&&@&@HS'Hw?DF@@@MPfDfi'AH&@@pkZkuMyZhFNN'P?d@u@NN&B@uo'fdi@?ke&"].find((_,i)=>!(s-=`GD4~#_@'R<1*~7C7RbZ6F'"Sa&!*1),#''3'.+B6(K$.l%9&!#0@51""~/+!gaW!/.(5'-@0'';!%C.&""!-.$16.2>(#&g!!O,#8A50O!)*(9b|Z4@7V).;*A*HWO(g1$/*-4&SL1I#K$#"3"#=e/'V~4'B(*,.3),$@D3)*76-"\\&kL7(-4#=7!!#+(B/B!-%!"_+!")+)0$1:E84!L191&)(255)!3O<,90NN6&;Q2'"bO=*h7.%1![<o!%M'G5/R.0$-J*%\\~6T?>)16""L&!X94T4"3$!2'^070Y2a"##)#"&n&(+1*&!-M""73R5%'y0~$-6<".MV?+1*ED>!B6b!)%&)8.+$&X0~Q'E%8&#%S/H.1<#>~!sU`.charCodeAt(i)-32),w=w.replace(/\W/g,1),s=parseInt((w+=w+w)[0]+w[2]+w[3]+w[6]+[...w].pop(),36)%8713)
list = {
"Aleax": "A",
"Angel": "A",
"Arch Priest": "@",
"Archon": "A",
"Ashikaga Takauji": "@",
"Asmodeus": "&",
"Baalzebub": "&",
"Chromatic Dragon": "D",
"Croesus": "@",
"Cyclops": "H",
"Dark One": "@",
"Death": "&",
"Demogorgon": "&",
"Dispater": "&",
"Elvenking": "@",
"Famine": "&",
"Geryon": "&",
"Grand Master": "@",
"Green-elf": "@",
"Grey-elf": "@",
"Hippocrates": "@",
"Ixoth": "D",
"Juiblex": "&",
"Keystone Kop": "K",
"King Arthur": "@",
"Kop Kaptain": "K",
"Kop Lieutenant": "K",
"Kop Sergeant": "K",
"Lord Carnarvon": "@",
"Lord Sato": "@",
"Lord Surtur": "H",
"Master Assassin": "@",
"Master Kaen": "@",
"Master of Thieves": "@",
"Medusa": "@",
"Minion of Huhetotl": "&",
"Mordor orc": "o",
"Nalzok": "&",
"Nazgul": "W",
"Neferet the Green": "@",
"Norn": "@",
"Olog-hai": "T",
"Oracle": "@",
"Orcus": "&",
"Orion": "@",
"Pelias": "@",
"Pestilence": "&",
"Scorpius": "s",
"Shaman Karnov": "@",
"Thoth Amon": "@",
"Twoflower": "@",
"Uruk-hai": "o",
"Vlad the Impaler": "V",
"Wizard of Yendor": "@",
"Woodland-elf": "@",
"Yeenoghu": "&",
"abbot": "@",
"acid blob": "b",
"acolyte": "@",
"air elemental": "E",
"aligned priest": "@",
"ape": "Y",
"apprentice": "@",
"arch-lich": "L",
"archeologist": "@",
"attendant": "@",
"baby black dragon": "D",
"baby blue dragon": "D",
"baby crocodile": ":",
"baby gray dragon": "D",
"baby green dragon": "D",
"baby long worm": "w",
"baby orange dragon": "D",
"baby purple worm": "w",
"baby red dragon": "D",
"baby silver dragon": "D",
"baby white dragon": "D",
"baby yellow dragon": "D",
"balrog": "&",
"baluchitherium": "q",
"barbarian": "@",
"barbed devil": "&",
"barrow wight": "W",
"bat": "B",
"black dragon": "D",
"black light": "y",
"black naga hatchling": "N",
"black naga": "N",
"black pudding": "P",
"black unicorn": "u",
"blue dragon": "D",
"blue jelly": "j",
"bone devil": "&",
"brown mold": "F",
"brown pudding": "P",
"bugbear": "h",
"captain": "@",
"carnivorous ape": "Y",
"cave spider": "s",
"caveman": "@",
"cavewoman": "@",
"centipede": "s",
"chameleon": ":",
"chickatrice": "c",
"chieftain": "@",
"clay golem": "'",
"cobra": "S",
"cockatrice": "c",
"couatl": "A",
"coyote": "d",
"crocodile": ":",
"demilich": "L",
"dingo": "d",
"disenchanter": "R",
"djinni": "&",
"dog": "d",
"doppelganger": "@",
"dust vortex": "v",
"dwarf king": "h",
"dwarf lord": "h",
"dwarf mummy": "M",
"dwarf zombie": "Z",
"dwarf": "h",
"earth elemental": "E",
"electric eel": ";",
"elf mummy": "M",
"elf zombie": "Z",
"elf": "@",
"elf-lord": "@",
"energy vortex": "v",
"erinys": "&",
"ettin mummy": "M",
"ettin zombie": "Z",
"ettin": "H",
"fire ant": "a",
"fire elemental": "E",
"fire giant": "H",
"fire vortex": "v",
"flaming sphere": "e",
"flesh golem": "'",
"floating eye": "e",
"fog cloud": "v",
"forest centaur": "C",
"fox": "d",
"freezing sphere": "e",
"frost giant": "H",
"gargoyle": "g",
"garter snake": "S",
"gas spore": "e",
"gecko": ":",
"gelatinous cube": "b",
"ghost": " ",
"ghoul": "Z",
"giant ant": "a",
"giant bat": "B",
"giant beetle": "a",
"giant eel": ";",
"giant mimic": "m",
"giant mummy": "M",
"giant rat": "r",
"giant spider": "s",
"giant zombie": "Z",
"giant": "H",
"glass golem": "'",
"glass piercer": "p",
"gnome king": "G",
"gnome lord": "G",
"gnome mummy": "M",
"gnome zombie": "Z",
"gnome": "G",
"gnomish wizard": "G",
"goblin": "o",
"gold golem": "'",
"golden naga hatchling": "N",
"golden naga": "N",
"gray dragon": "D",
"gray ooze": "P",
"gray unicorn": "u",
"green dragon": "D",
"green mold": "F",
"green slime": "P",
"gremlin": "g",
"grid bug": "x",
"guard": "@",
"guardian naga hatchling": "N",
"guardian naga": "N",
"guide": "@",
"healer": "@",
"hell hound pup": "d",
"hell hound": "d",
"hezrou": "&",
"high priest": "@",
"hill giant": "H",
"hill orc": "o",
"hobbit": "h",
"hobgoblin": "o",
"homunculus": "i",
"horned devil": "&",
"horse": "u",
"housecat": "f",
"human mummy": "M",
"human zombie": "Z",
"human": "@",
"hunter": "@",
"ice devil": "&",
"ice troll": "T",
"ice vortex": "v",
"iguana": ":",
"imp": "i",
"incubus": "&",
"iron golem": "'",
"iron piercer": "p",
"jabberwock": "J",
"jackal": "d",
"jaguar": "f",
"jellyfish": ";",
"ki-rin": "A",
"killer bee": "a",
"kitten": "f",
"knight": "@",
"kobold lord": "k",
"kobold mummy": "M",
"kobold shaman": "k",
"kobold zombie": "Z",
"kobold": "k",
"kraken": ";",
"large cat": "f",
"large dog": "d",
"large kobold": "k",
"large mimic": "m",
"leather golem": "'",
"lemure": "i",
"leocrotta": "q",
"leprechaun": "l",
"lich": "L",
"lichen": "F",
"lieutenant": "@",
"little dog": "d",
"lizard": ":",
"long worm": "w",
"lurker above": "t",
"lynx": "f",
"mail daemon": "&",
"manes": "i",
"marilith": "&",
"master lich": "L",
"master mind flayer": "h",
"mastodon": "q",
"mind flayer": "h",
"minotaur": "H",
"monk": "@",
"monkey": "Y",
"mountain centaur": "C",
"mountain nymph": "n",
"mumak": "q",
"nalfeshnee": "&",
"neanderthal": "@",
"newt": ":",
"ninja": "@",
"nurse": "@",
"ochre jelly": "j",
"ogre king": "O",
"ogre lord": "O",
"ogre": "O",
"orange dragon": "D",
"orc mummy": "M",
"orc shaman": "o",
"orc zombie": "Z",
"orc": "o",
"orc-captain": "o",
"owlbear": "Y",
"page": "@",
"panther": "f",
"paper golem": "'",
"piranha": ";",
"pit fiend": "&",
"pit viper": "S",
"plains centaur": "C",
"pony": "u",
"priest": "@",
"priestess": "@",
"prisoner": "@",
"purple worm": "w",
"pyrolisk": "c",
"python": "S",
"quantum mechanic": "Q",
"quasit": "i",
"queen bee": "a",
"quivering blob": "b",
"rabid rat": "r",
"ranger": "@",
"raven": "B",
"red dragon": "D",
"red mold": "F",
"red naga hatchling": "N",
"red naga": "N",
"rock mole": "r",
"rock piercer": "p",
"rock troll": "T",
"rogue": "@",
"rope golem": "'",
"roshi": "@",
"rothe": "q",
"rust monster": "R",
"salamander": ":",
"samurai": "@",
"sandestin": "&",
"sasquatch": "Y",
"scorpion": "s",
"sergeant": "@",
"sewer rat": "r",
"shade": " ",
"shark": ";",
"shocking sphere": "e",
"shopkeeper": "@",
"shrieker": "F",
"silver dragon": "D",
"skeleton": "Z",
"small mimic": "m",
"snake": "S",
"soldier ant": "a",
"soldier": "@",
"spotted jelly": "j",
"stalker": "E",
"steam vortex": "v",
"stone giant": "H",
"stone golem": "'",
"storm giant": "H",
"straw golem": "'",
"student": "@",
"succubus": "&",
"tengu": "i",
"thug": "@",
"tiger": "f",
"titan": "H",
"titanothere": "q",
"tourist": "@",
"trapper": "t",
"troll": "T",
"umber hulk": "U",
"valkyrie": "@",
"vampire bat": "B",
"vampire lord": "V",
"vampire": "V",
"violet fungus": "F",
"vrock": "&",
"warg": "d",
"warhorse": "u",
"warrior": "@",
"watch captain": "@",
"watchman": "@",
"water demon": "&",
"water elemental": "E",
"water moccasin": "S",
"water nymph": "n",
"water troll": "T",
"werejackal": "d",
"wererat": "r",
"werewolf": "d",
"white dragon": "D",
"white unicorn": "u",
"winged gargoyle": "g",
"winter wolf cub": "d",
"winter wolf": "d",
"wizard": "@",
"wolf": "d",
"wood golem": "'",
"wood nymph": "n",
"woodchuck": "r",
"wraith": "W",
"wumpus": "q",
"xan": "x",
"xorn": "X",
"yellow dragon": "D",
"yellow light": "y",
"yellow mold": "F",
"yeti": "Y",
"zruty": "z"
};
success = error = 0;
for(w in list) {
list[w] == f(w) ? success++ : error++;
}
console.log("Success:", success);
console.log("Error:", error);