16
\$\begingroup\$

The naming conventions for games in the Super Mario series is very strange, and don't match up between regions.

| Japanese Name       | American Name                      |
|---------------------|------------------------------------|
| Super Mario Bros.   | Super Mario Bros.                  |
| Super Mario Bros. 2 | Super Mario Bros.: The Lost Levels |
| Super Mario USA     | Super Mario Bros. 2                |
| Super Mario Bros. 3 | Super Mario Bros. 3                |
| Super Mario Bros. 4 | Super Mario World                  |

What a mess!


Challenge:

Given a string consisting of the Japanese name of a Super Mario game, output the corresponding American name. You may input the Japanese string through any reasonable method, and output the American string (with an optional newline) through any reasonable method.

You must use the exact strings shown above. Standard loopholes are forbidden!

The shortest code (in bytes) is the winner.

\$\endgroup\$
  • 1
    \$\begingroup\$ codegolf.meta.stackexchange.com/questions/8047/… try to avoid fancy tables... \$\endgroup\$ – Roman Gräf Jun 2 '17 at 8:08
  • 1
    \$\begingroup\$ But I thought the Japanese name for Super Mario Bros. 2 was Doki Doki Panic. Or did they re-release the same game in Japan again but with the Mario skins? \$\endgroup\$ – Shufflepants Jun 2 '17 at 15:08
  • \$\begingroup\$ @Shufflepants IIRC, yes, they did re-release it with Mario skins as "Super Mario USA". \$\endgroup\$ – Pokechu22 Jun 2 '17 at 15:15
  • 1
    \$\begingroup\$ Can we assume the input must be the exact Japanese names? \$\endgroup\$ – stevefestl Jun 14 '17 at 11:13
  • 1
    \$\begingroup\$ @SteveFest Yes. \$\endgroup\$ – Julian Lachniet Jun 14 '17 at 14:43

15 Answers 15

14
\$\begingroup\$

sed, 52

  • 1 byte saved thanks to @MikeScott

Straightforward replacement:

s/ 2/: The Lost Levels/
s/USA/Bros. 2/
s/B.*4/World/

Try it online.

\$\endgroup\$
  • 2
    \$\begingroup\$ You can save a character by making the last line s/B.*4/World/. \$\endgroup\$ – Mike Scott Jun 2 '17 at 11:52
  • \$\begingroup\$ @MikeScott yes - thanks! \$\endgroup\$ – Digital Trauma Jun 2 '17 at 17:39
6
\$\begingroup\$

Retina, 43

  • 1 byte saved thanks to @MikeScott

Direct port of my sed answer:

 2
: The Lost Levels
USA
Bros. 2
B.*4
World

Try it online.

\$\endgroup\$
  • \$\begingroup\$ My saved character from the sed version works here too -- use B.*4 instead of \S* 4. \$\endgroup\$ – Mike Scott Jun 2 '17 at 11:56
6
\$\begingroup\$

JavaScript (ES6), 82 81 bytes

s=>s.replace(/ 2|o.*4|USA/,(_,i)=>['Bros. 2',': The Lost Levels','o World'][i&3])

Try it online!

How?

There are three patterns to look for and replace. We search all of them at once and use the position \$i\$ of the match to deduce the substitution string.

Pattern | Found in              | Position in string | Position MOD 4 | Replaced with
--------+-----------------------+--------------------+----------------+--------------------
/ 2/    | "Super Mario Bros. 2" |                 17 |              1 | ": The Lost Levels"
/o.*4/  | "Super Mario Bros. 4" |                 10 |              2 | "o World"
/USA/   | "Super Mario USA"     |                 12 |              0 | "Bros. 2"
\$\endgroup\$
  • 2
    \$\begingroup\$ Now that's clever. \$\endgroup\$ – darrylyeo Jun 2 '17 at 15:17
5
\$\begingroup\$

PHP, 81 Bytes

<?=str_replace([" 2",USA,"Bros. 4"],[": The Lost Levels","Bros. 2",World],$argn);

Try it online!

\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES6), 84 bytes

s=>s[r='replace'](' 2',': The Lost Levels')[r]('USA',(b='Bros. ')+2)[r](b+4,'World')

f=
s=>s[r='replace'](' 2',': The Lost Levels')[r]('USA',(b='Bros. ')+2)[r](b+4,'World')

console.log(
    f('Super Mario Bros.'),
    f('Super Mario Bros. 2'),
    f('Super Mario USA'),
    f('Super Mario Bros. 3'),
    f('Super Mario Bros. 4')
)

\$\endgroup\$
  • 2
    \$\begingroup\$ +1 for the [r='replace'] trick. \$\endgroup\$ – Arjun Jun 2 '17 at 6:04
  • \$\begingroup\$ I don't know JS much... how does using the [] work as a function? \$\endgroup\$ – totallyhuman Jun 3 '17 at 0:53
  • 3
    \$\begingroup\$ @totallyhuman 1) JS object properties can be accessed with either of these two syntaxes: object.property or object['property']. 2) A method of an object is a property that is assigned a function. 3) Under the hood, JS briefly turns a primitive type such as a string into an object when a property access syntax is used on it. Conclusion: by combining all of the above, we can understand why s['replace']() does exactly what it says on the tin. \$\endgroup\$ – Arnauld Jun 3 '17 at 13:44
3
\$\begingroup\$

Python 2, 96 92 bytes

lambda s:r(r(r(s,' 2',': The Lost Levels'),'USA','Bros. 2'),'Bros. 4','World')
r=str.replace

Try it online!

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

Japt, 48 bytes

d" 2"`: T” Lo¡ Levels`"USA"`Bžs. 2``Bžs. 4``WŽld

Try it online!

Explanation:

 d" 2"`: T&#148; Lo¡ Levels`"USA"`B&#158;s. 2``B&#158;s. 4``W&#142;ld

U                                //  Implicit U = Input
 d                               //  Replace:
   " 2"                          //    " 2" with
       `...`                     //    ": The Lost Levels" decompressed,
            "USA"                //    "USA" with
                 '...'           //    "Bros. 2" decompressed,
                      '...'      //    "Bros. 4" decompressed with
                           '...' //    "World" decompressed

Japt uses the shoco library for string compression. Backticks are used to decompress strings.

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

R, 86 bytes

function(x)sub("Bros. 4","World",sub("USA","Bros. 2",sub(" 2",": The Lost Levels",x)))
\$\endgroup\$
1
\$\begingroup\$

Jelly,  44  43 bytes

⁹
HḂ+2⁹Ḳ¤ḣK;⁸ị“¥ḄḞ“ḋṗYP8ḷẇ?Ṅ“¡Ạ ṙṗ%»¤
0ịVĊŀ

A full program that prints the result.

Try it online!

How?

⁹ - Link 1: yield right argument: number a, list of characters b
⁹ - link's right argument, b

HḂ+2⁹Ḳ¤ḣK;⁸ị“¥ḄḞ“ḋṗYP8ḷẇ?Ṅ“¡Ạ ṙṗ%»¤ - Link 0: change a name: number a, list of characters b
                   ...Note: at this point a will be 0, 2 or 4 for USA, 2 and 4 respectively
H                                   - halve a (0,1, or 2)
 Ḃ                                  - mod 2   (0,1, or 0)
  +2                                - add 2   (2,3, or 2)
      ¤                             - nilad followed by link(s) as a nilad:
    ⁹                               -   link's right argument, b
     Ḳ                              -   split at spaces
       ḣ                            - head (first two for USA or 4, first three for 2)
        K                           - join with spaces
                                  ¤ - nilad followed by link(s) as a nilad:
          ⁸                         -   link's left argument a
            “¥ḄḞ“ḋṗYP8ḷẇ?Ṅ“¡Ạ ṙṗ%»  -   list of dictionary/string compresions:
                                    -     [" World",": The Lost Levels"," Bros. 2"]
           ị                        - index into (1-based & modular; respectively [4,2,0])

0ịVĊŀ - Main link: list of characters, J
0ị    - index 0 into J - gets the last character '.', '2', 'A', '3', or '4'
  V   - evaluate as Jelly code - the evaluations are:
      -     "Super Mario Bros." :  . - literal 0.5
      -   "Super Mario Bros. 2" :  2 - literal 2
      -       "Super Mario USA" :  A - absolute value (default argument is 0) = 0
      -   "Super Mario Bros. 3" :  3 - literal 3
      -   "Super Mario Bros. 4" :  4 - literal 4
   Ċ  - ceiling - changes a 0.5 to 1 and leaves others as they were
    ŀ - call link at that index as a dyad (left = the evaluation, right = J)
      -   this is one based and modular so 1 & 3 go to Link 1, while 0, 2 & 4 go to Link 0.
\$\endgroup\$
  • 3
    \$\begingroup\$ Nice workaround to "crossed-out 44 is normal 44". \$\endgroup\$ – wizzwizz4 Jun 2 '17 at 12:43
1
\$\begingroup\$

Mathematica, 80 bytes

#~StringReplace~{" 2"->": The Lost Levels","USA"->"Bros. 2","Bros. 4"->"World"}&

Anonymous function. Takes a string as input and returns a string as output.

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

Python 3: 111 bytes

from re import sub as r
print(r(" USA","Bros. 2",r(" 2",": The Lost Levels",r("Bros. 4","World",input()))))

Gets user input, runs a series of regex-based substitutions, and prints the result.

\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! I think it's shorter if you do from re import* instead of from re import sub as r. Then the second line would become: print(sub(" USA","Bros. 2",sub(" 2",": The Lost Levels",sub("Bros. 4","World",input())))) \$\endgroup\$ – DJMcMayhem Jun 2 '17 at 15:16
  • \$\begingroup\$ Aha, excellent. Thank you! \$\endgroup\$ – Struan Duncan-Wilson Jun 7 '17 at 14:28
0
\$\begingroup\$

Go, 134 bytes

import."strings"
func f(s string)string{r:=Replace;return r(r(r(s," 2",": The Lost Levels",1),"USA","Bros. 2",1),"Bros. 4","World",1)}

Try it online!

Since Go doesn't support default values for arguments, you have to manually pass 1 every time.

\$\endgroup\$
0
\$\begingroup\$

Batch, 237 99 bytes

Assuming input is in exact format in the question

@set s=%*
@set s=%s: 2=: The Lost Levels%
@set s=%s:USA=Bros. 2%
@set s=%s:Bros. 4=World%
@echo %s%
\$\endgroup\$
0
\$\begingroup\$

Pascal (FPC), 184 182 bytes

const s='Super Mario ';b='Bros.';m=s+b;var t:string;z:array[0..4]of string=(m+' 2',m+' 3',m,s+'World',m+': The Lost Levels');begin read(t);write(z[(length(t)+ord(t[19])*2)mod 5])end.

Try it online!

Explanation:

z is the array that holds 5 possible outputs, we just need to find the way to index into it. I noticed 2 parameters that can be used to distinguish input. The first part is length of the input:

Super Mario Bros.   -> 17
Super Mario Bros. 2 -> 19
Super Mario USA     -> 15
Super Mario Bros. 3 -> 19
Super Mario Bros. 4 -> 19

Only 3 inputs have the same length mod 5. The second part is that, at position 19 in the inputs, 2, 3 and 4 have consecutive code points, so they can be easily used to fill out the rest of the indexes while the remaining 2 inputs are shorter.

The String type defaults to ShortString and by default has capacity for 255 characters, all initialized with zeroes, so it is safe to use t[19] on all strings and its codepoint is 0 for shorter strings, not changing anything for indexing, so shorter strings' indexes are 0 and 2. Therefore, we need indexes 1, 3 and 4 from 2, 3 and 4.

  | Codepoint |  *2 | +19 | mod 5
2 |        50 | 100 | 119 | 4
3 |        51 | 102 | 121 | 1
4 |        52 | 104 | 123 | 3
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 37 bytes

l„ 2“:€€‹×Œä“:'„À"bros. 2"©:®Y4:'‚ï:™

Try it online or verify all test cases.

Explanation:

l                  # Convert the input to lowercase
 „ 2         :     # Replace " 2" with:
    “:€€‹×Œä“      #  ": the lost levels"
 '„À          :    # Then replace "usa" with:
    "bros. 2"      #  "bros. 2"
             ©     # And store the string "bros. 2" in the register
 ®                 # Retrieve "bros. 2" from the register,
  Y4:              # and replace its "2" with "4"
        :          # Then replace "bros. 4" with:
     '‚ï           #  "world"
™                  # Convert the result to title-case (and output implicitly)

See this for more information why “:€€‹×Œä“ is ": the lower levels"; '„À is "usa"; and '‚ï is "world".

\$\endgroup\$

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.