I'm a huge video game music fan. One of my favorite OSTs is that from Kingdom Hearts, by Yoko Shimomura.

The challenge

Create a program or function that takes two arguments in any format: an abbreviated Kingdom Hearts game and a boss in that game. It must return the name of the song that plays for that boss. The program should handle any input case, but you can decide what case the output will be. You may assume the input is always valid. Here is a list of all the valid inputs:

Game   Boss                       Song

1      Ansem                      Guardando nel Buio
1      Riku                       Forze de Male
1      Sephiroth                  One Winged Angel
1      Kurt Zisa                  The Deep End
1      Unknown                    Disappeared
2      Organization XIII          The 13th Struggle, Dilemma, Reflection
2      Xemnas I                   A Fight to the Death
2      Xemnas II                  Darkness of the Unknown
2      Sephiroth                  One Winged Angel
2      Lingering Sentiment        Rage Awakened
CoM    Organization XIII          The 13th Struggle
CoM    Marluxia 1                 Graceful Assasin
CoM    Marluxia 2                 Scythe of Petals
CoM    Marluxia 3                 Lord of the Castle
CoM    Riku Replica               The Force in You
CoM    Ansem                      Revenge of Chaos
BBS    Master Xehanort            Black Powder
BBS    Terra vs Master Xehanort   Rage Awakened
BBS    Vanitas                    Enter the Darkness
BBS    Ventus vs Vanitas          The Key
BBS    Vanitas Remnant            Enter the Void
BBS    Terranort                  Dismiss
BBS    Mysterious Figure          Dark Impetus
Coded  Riku                       Riku
Coded  Pete                       Rowdy Rumble
Coded  Maleficent                 Vim and Vigor
Coded  Sora's Heartless           Guardando nel Buio
Coded  Roxas                      The Other Promise
Days   Xion                       Vector to the Heavens
Days   Riku                       Another Side
DDD    Anti Black Coat Nightmare  Dread of Night
DDD    Ansem I                    L'Eminenza Oscura I
DDD    Ansem II                   L'Eminenza Oscura II
DDD    Xemnas                     L'Oscurita dell'Ignoto
DDD    Young Xehanort             L'Impeto Oscuro
DDD    Armored Ventus Nightmare   Eye of Darkness
DDD    Julius                     The Encounter

Scoring

Your score is not your byte count. You do not need to implement the entire list, but you must implement at least 10 items. Your score is byte count / # of items implemented. For instance, say you write a 90-byte program that implements 25 items of the above table. Your score would be 90/25=3.6. Lowest score wins.

Bonus

  • -1 off your score of you implement an additional item, from Final Fantasy:

    Game    Boss        Song
    
    XV      Behemoth    Omnis Lacrima
    

    AND make it so that any other requested bosses from XV return TBD.

  • -0.5 if your code also takes in the games 1.5 and 2.5, which take the same bosses as 1 and 2 but return the song name followed by (Orchestrated).

  • Another -0.5 if your program accepts bosses from CoM and Days when given 1.5 and accepts bosses from Coded and BBS when given 2.5. It must return the songs followed by (Orchestrated).

If you know of any other significant bosses I left out, let me know in the comments.

Also, I'm hoping I'm not the only person here who has memorized all of these songs...

  • So if I use a language that writes text to stdout (HTML perhaps) the program Riku would give me a score of 4/1=1. I wonder if there's a language where the empty program would echo the second argument to STDOUT. Then for the input Coded,Riku I could have the score 0/1=0. Hmm... – Level River St Jul 23 '15 at 22:41
  • You may want to require that at least 1 item needs to be implemented. Otherwise somebody could submit a 0 length program that implements 0 items. Well, then the next question would be about the value of 0/0... – Reto Koradi Jul 23 '15 at 22:42
  • @steveverrill I was just about to submit a solution that prints "Riku". I guess the idea was obvious enough... – Reto Koradi Jul 23 '15 at 22:45
  • 1
    @steveverill I updated the question so that at least 10 items must be implemented. – kirbyfan64sos Jul 23 '15 at 22:52
  • 1
    @MarchHo Actually, it seems the standard loopholes have been renamed to loopholes that are forbidden by default. So it's not necessary to mention them explicitly. – orlp Jul 24 '15 at 1:39
up vote 4 down vote accepted
+50

Ruby 134 131/10=13.1

->g,b{"Rowdy Rumble|Dread of Night|Riku|One Winged Angel|Rage Awakened|Vim and Vigor|The Key|The 13th Struggle".split(?|)[b.ord%8]}

This is a lambda function, which takes arguments for the game and the boss. The argument for the game is actually ignored by the code, but the OP has clarified that the argument cannot be eliminated.

In fact it only uses the first letter of the boss's name. the ASCII code is taken modulo 8 (this gives the same answer for a given letter, regardless of case) and one of 8 song titles is returned. As two song titles appear twice, this covers a total of 10 elements:

Game   Boss                      Array  Song
                                 index
Coded  Pete                         0   Rowdy Rumble
DDD    Anti Black Coat Nightmare    1   Dread of Night
Coded  Riku                         2   Riku
1      Sephiroth                    3   One Winged Angel
2      Sephiroth                    3   One Winged Angel
2      Lingering Sentiment          4   Rage Awakened
BBS    Terra vs Master Xehanort     4   Rage Awakened
Coded  Maleficent                   5   Vim and Vigor
BBS    Ventus vs Vanitas            6   The Key
CoM    Organization XIII            7   The 13th Struggle

It was a lucky coincidence that the Ascii codes for L and T give the same result modulo 8, so both incidences of Rage Awakened could be covered.

Call the function as in this test program:

f=->g,b{"Rowdy Rumble|Dread of Night|Riku|One Winged Angel|Rage Awakened|Vim and Vigor|The Key|The 13th Struggle".split(?|)[b.ord%8]}
B=gets                  #get boss name from stdin
puts f.call("dummy",B)  #call function, and output return value to stdout
  • Wow! I've never seen Ruby beat Pyth before! – kirbyfan64sos Aug 3 '15 at 1:28
  • @kirbyfan64sos That's kind of why I entered the challenge, I saw an opportunity for Ruby to beat a golfing language. It really is more about picking the items to implement than anything else. My code is 105 data (including quote marks but excluding .split) + 29 program. @Orlp 's is 124 data + 20 program. BTW, do I have to include the g,? It doesn't do anything. The question says "two arguments" but in "any format" (which might mean one argument could be not taken at all, so I'm not sure.) – Level River St Aug 3 '15 at 1:51
  • @steveverill What do you mean by g,? – kirbyfan64sos Aug 3 '15 at 1:53
  • @kirbyfan64sos I mean my code takes two arguments for the game and boss: ->g,b{...} but the game argument is in fact ignored by the code. So I wondered if I had to count those two characters g, or if I could eliminate them and just have one argument: ->b{...} – Level River St Aug 3 '15 at 1:59
  • @steveverill It's needed. I doubt that's an issue for your answer, though... :) – kirbyfan64sos Aug 3 '15 at 2:06

Pyth, 144/10 = 14.4

@c"|L'Impeto Oscuro|Riku|Eye of Darkness|Disappeared||Another Side|Forze de Male|Dread of Night|Rowdy Rumble|One Winged Angel"\|%.hrzZ11

Incredibly simple hash table, with the 'coincidence' of re-using the song 'One Winged Angel' twice. The above program recognizes the following items correctly:

ddd young xehanort            | L'Impeto Oscuro
coded riku                    | Riku
ddd armored ventus nightmare  | Eye of Darkness
1 mysterious figure           | Disappeared
days riku                     | Another Side
1 riku                        | Forze de Male
ddd anti black coat nightmare | Dread of Night
coded pete                    | Rowdy Rumble
1 sephiroth                   | One Winged Angel
2 sephiroth                   | One Winged Angel
  • Does it accept the uppercase variants of the games too? – kirbyfan64sos Jul 24 '15 at 1:35
  • The challenge says it should handle any input case... – kirbyfan64sos Jul 24 '15 at 1:36
  • When I said "the user", I meant the user of the program, not the developer. :) – kirbyfan64sos Jul 24 '15 at 1:36
  • 2
    @kirbyfan64sos The new scoring makes no sense, provides no incentive to implement anything more than 10 items, and is contradictory in the question (you still say 90/25=3.6). Plus, changing the scoring after answers have been posted is bad manner, unless you're patching up a very obvious loophole. – orlp Jul 24 '15 at 2:08
  • 1
    Save a byte by separating by linebreaks, then c by b. – Maltysen Jul 24 '15 at 2:42

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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