일본 마리오 타이틀을 미국 타이틀로 변환


16

슈퍼 마리오 시리즈 게임의 명명 규칙은 매우 이상하며 지역간에 일치하지 않습니다.

| 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                  |

엉망이야!


도전:

슈퍼 마리오 게임의 일본어 이름으로 구성된 문자열이 주어지면 해당하는 미국 이름을 출력합니다. 합리적인 방법으로 일본어 문자열을 입력하고 합리적인 방법으로 미국식 문자열 (선택적인 줄 바꿈)을 출력 할 수 있습니다.

위에 표시된 정확한 문자열을 사용해야합니다. 표준 허점은 금지되어 있습니다!

가장 짧은 코드 (바이트)가 승자입니다.


1
codegolf.meta.stackexchange.com/questions/8047/… 멋진 테이블을 피하려고 노력하십시오.
Roman Gräf

1
그러나 Super Mario Bros. 2의 일본 이름은 Doki Doki Panic이라고 생각했습니다. 아니면 일본에서 같은 게임을 다시 출시했지만 마리오 스킨으로 다시 출시 했습니까?
Shufflepants 2016 년

@Shufflepants IIRC, 그렇습니다. "슈퍼 마리오 USA"라는 마리오 스킨으로 다시 출시했습니다.
Pokechu22

1
입력이 정확한 일본어 이름이어야한다고 가정 할 수 있습니까?
stevefestl

1
@SteveFest 예.
Julian Lachniet

답변:




6

자바 스크립트 (ES6), 82 81 바이트

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

온라인으로 사용해보십시오!

어떻게?

나는

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"

2
이제는 영리합니다.
darrylyeo


3

자바 스크립트 (ES6), 84 바이트

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


2
[r='replace']트릭에 +1
Arjun

나는 JS를 많이 모른다. 어떻게 []작업을 함수로 사용 하는가?
완전히 인간적인

3
@totallyhuman 1) JS 객체 속성이 두 구문 중 하나에 액세스 할 수있다 : object.property또는 object['property']. 2) 객체의 메소드는 함수가 할당 된 속성입니다. 3) JS는 속성 액세스 구문이 사용될 때 문자열과 같은 기본 유형을 간단히 객체로 바꿉니다 . 결론 : 위의 모든 내용을 결합 s['replace']()하여 주석에서 정확히 무엇을 말하는지 이해할 수 있습니다 .
Arnauld


2

apt , 48 바이트

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

온라인으로 사용해보십시오!

설명:

 d" 2"`: T” Lo¡ Levels`"USA"`Bžs. 2``Bžs. 4``WŽ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는 문자열 압축을 위해 shoco 라이브러리 를 사용합니다 . 백틱은 문자열을 압축 해제하는 데 사용됩니다.



1

젤리 ,  44  43 바이트

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

결과를 인쇄하는 전체 프로그램.

온라인으로 사용해보십시오!

어떻게?

⁹ - 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.

3
"교차 된 44는 보통 44"입니다.
wizzwizz4 2016 년

1

Mathematica, 80 바이트

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

익명의 기능. 문자열을 입력으로 받아서 문자열을 출력으로 반환합니다.


1

파이썬 3 : 111 바이트

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

사용자 입력을 가져오고 일련의 정규식 기반 대체를 실행하고 결과를 인쇄합니다.


사이트에 오신 것을 환영합니다! 나는 당신이 from re import*대신 하는 것이 더 짧다고 생각합니다 from re import sub as r. 두 번째 줄은 다음과 같습니다.print(sub(" USA","Bros. 2",sub(" 2",": The Lost Levels",sub("Bros. 4","World",input()))))
DJMcMayhem

아하, 훌륭합니다. 감사합니다!
Struan Duncan-Wilson


0

배치, 237 99 바이트

질문에 입력이 정확한 형식이라고 가정

@set s=%*
@set s=%s: 2=: The Lost Levels%
@set s=%s:USA=Bros. 2%
@set s=%s:Bros. 4=World%
@echo %s%

0

파스칼 (FPC) , 184182 바이트

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.

온라인으로 사용해보십시오!

설명:

z5 개의 가능한 출력을 보유하는 배열이므로 색인을 생성하는 방법을 찾아야합니다. 입력을 구별하는 데 사용할 수있는 2 개의 매개 변수를 발견했습니다. 첫 번째 부분은 입력 길이입니다.

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

3 개의 입력 만 길이 mod 5가 동일합니다. 두 번째 부분은 입력의 19 번 위치에서 2, 34 그들은 쉽게 나머지 2 개 입력 인 반면 인덱스의 나머지를 채우기 위해 사용될 수 있으므로, 연속 된 코드 포인트를 더 짧습니다.

String에 유형 기본값 ShortString은 안전하게 사용할 수 있도록 기본적으로는, 255 자 용량, 모두 0으로 초기화를 가지고 t[19]모든 문자열과의 코드 포인트는 짧은 문자열을 0, 인덱싱을 위해 아무 것도 변경하지 않는, 그래서 짧은 문자열 '인덱스는 0이며, 2. 따라서, 우리는 인덱스 1, 3, 4가 필요합니다 2, 3하고 4.

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

0

05AB1E , 37 바이트

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

온라인으로 시도 하거나 모든 테스트 사례를 확인하십시오.

설명:

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)

더 자세한 정보 “:€€‹×Œä“는 이것을 참조하십시오 ": the lower levels". '„À이다 "usa"; 하고 '‚ï있다 "world".

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.