큰 코드 ... 당신을 위해!


32

다크 나이트 의 개막 현장 에서 CIA 요원과 악당 베인 사이에는 다소 어색한 대화 가 있습니다.

CIA 요원 : "그 [마스크]를 벗으면 죽겠습니까?"

베인 : “매우 고통 스러울 것입니다…”

CIA 요원 : "당신은 큰 사람입니다."

바람개비 : “… 당신을 위해.”

베인이“당신을 위해 고통 스럽다”또는“당신을 위해 큰 사람”이라고 말하려고하는지 확실하지 않습니다. 코드 골프를 통해이 문제를 한번에 해결합시다!

도전

당신의 작업은 입력으로 주어진 정수에 따라 위의 대화를 재정렬하는 프로그램을 작성하는 것입니다.

CIA 상담원 대화 단어는 다음과 같습니다. If I pull that off will you die? You're a big guy.

베인의 대화 단어는 다음과 같습니다. It would be extremely painful... for you!

유의하시기 바랍니다 die?, You’re, painful...그리고 you!하나의 단어로 간주됩니다.

  1. 정수 n이 입력으로 주어지면 이진수로 변환
  2. 이진수를 왼쪽에서 오른쪽으로 읽으면 숫자가이면 CIA 에이전트 대화 상자 1에서 다음 단어를, 숫자가이면 Bane 대화 상자에서 다음 단어를 출력하십시오 0. 단어는 공백으로 구분해야합니다. 스피커가 바뀌면 줄 바꿈을 추가하십시오. 또한 각 대화 줄 앞에 발표자 이름 ( BANE:또는 CIA:)을 붙 입니다.

입력은 항상 이진 형식의 1로 시작하고 12는 1이고 7은 0이라고 가정 할 수 있습니다.

522300

  1. 이진으로 변환 : 1111111100000111100

  2. 숫자는 8 개로 시작하므로 CIA의 상담원 대화에서 8 개의 첫 단어를 출력하고 CIA로 접두어를 붙입니다. CIA: If I pull that off will you die?

  3. 그리고 우리는 5 개의 0을 얻었고, Bane의 대화에서 5 개의 첫 단어를 얻었습니다 BANE: It would be extremely painful...

  4. 그런 다음 4 개의 단어가 있으므로 4 개의 다음 CIA 단어를 출력합니다. CIA: You’re a big guy.

  5. 그런 다음 2 개의 0 BANE: for you!

최종 결과:

CIA: If I pull that off will you die?
BANE: It would be extremely painful...
CIA: You’re a big guy.
BANE: for you!

더 많은 테스트 사례 :

494542

CIA: If I pull that
BANE: It would be
CIA: off
BANE: extremely
CIA: will you die? You're
BANE: painful... for
CIA: a big guy.
BANE: you!

326711

CIA: If
BANE: It would
CIA: I pull that off will you
BANE: be extremely painful... for
CIA: die? You're
BANE: you!
CIA: a big guy.

각 줄은 공백으로 끝날 수 있습니까?
xnor

@ xnor 예, 괜찮습니다.
Arnaud 2012

와 "이"파멸의 연설의 첫 단어로 테스트 케이스에 / 견적 일치하지 않는다 "고"
MildlyMilquetoast

@ 미스타는 "그것"으로 고정, 감사합니다!
Arnaud 2012

3
나 또는 누군가가 바람둥이의 목소리로 대화를 읽습니까?
Gurupad Mamadapur

답변:


10

Pyth-138 바이트

영화 스크립트를 압축해야합니다.

K_cc"guy big a You're die? you will off that pull I If you! for painful... extremely be would That"d12jmj;++@c"BANECIA"4ed\:m.)@Kedhdr8jQ2

테스트 스위트 .


7

자바 스크립트 (ES6) 203 201 바이트

편집 : ETHproductions 답변 에서 trim()아이디어를 뻔뻔스럽게 빌려 2 바이트를 절약했습니다.

n=>"If I pull that off will you die? You're a big guy. It would be extremely painful... for you!".split` `.map((_,i,a)=>[`
BANE: `,`
CIA: `,' '][j^(j=n>>18-i&1)?j:2]+a[k[j]++],k=[j=12,0]).join``.trim()

테스트 사례


7

자바 스크립트 (ES6) 209 202 201 바이트

(n,a="It would be extremely painful... for you! If I pull that off will you die? You're a big guy.".split` `,b=[6,18])=>(F=(s,p=n%2)=>n?F((p^(n>>=1)%2?p?`
CIA: `:`
BANE: `:` `)+a[b[p]--]+s):s.trim())``

오래된 접근법 :

(n,a="If I pull that off will you die? You're a big guy. It would be extremely painful... for you!".split` `,b=[12,0])=>(F=p=>p^n%2?F(n%2)+(p?`
CIA:`:`
BANE:`):n?F(p,n>>=1)+" "+a[b[p]++]:``)(n%2).trim()

테스트 스 니펫

f=(n,a="It would be extremely painful... for you! If I pull that off will you die? You're a big guy.".split` `,b=[6,18])=>(F=(s,p=n%2)=>n?F((p^(n>>=1)%2?p?`
CIA: `:`
BANE: `:` `)+a[b[p]--]+s):s.trim())``

console.log(f(522300))
console.log(f(494542))
console.log(f(326711))


나는 당신의 trim()생각을 뻔뻔스럽게 빌리고 있습니다 . 나는 더 좋은 것이 slice(1)있지만 그것을 알아낼 수 없었다고 확신했다.
Arnauld

@Arnauld 나와 함께하면, 이제 우리는 묶여 있습니다. 나는 200 미만에서 그것을 할 수있는 방법이 내기 :-)
ETHproductions

6

C ++ 11 (GCC), 298 293 바이트

#include<sstream>
[](int i){std::stringstream b("It would be extremely painful... for you!"),c("If I pull that off will you die? You're a big guy.");std::string s,w;int n=0,t=i,p;while(t/=2)n++;for(;n>=0;p=t)((t=i>>n&1)?c:b)>>w,s+=p^t?t?"CIA: ":"BANE: ":" ",s+=t^(i>>--n)&1?w+"\n":w;return s;}

정수를 가져 와서 대화 상자를로 반환하는 람다 함수입니다 std::string. 여기 에서 실제로 볼 수 있습니다 .

언 골프 버전 (일부 설명 포함) :

#include<sstream>

[](int i) {
    std::stringstream bane("It would be extremely painful... for you!"),
                      cia("If I pull that off will you die? You're a big guy.");
    std::string s, w;
    int n = 0, t = i, p;
    // Find the position of the most significant bit (n)
    while (t/=2) n++;

    for (; n>=0; p=t) {
        t = i>>n&1; // Current bit
        // Append the speaker name if the previous bit was different
        if (t != p) s += (t ? "CIA: " : "BANE: ");
        else s += " ";

        // Read the next word from one of the streams
        if (t) cia >> w;
        else bane >> w;

        s += w;

        if (t != ((i>>--n)&1)) // Append a newline if the next bit is different
            s += "\n";
    }

    return s;
}

4

자바 스크립트 (ES6) 252 227 226 바이트

n=>[...n.toString(2,b="If I pull that off will you die? You're a big guy.".split` `,c="It would be extremely painful... for you!".split` `)].map((a,i,j)=>(a!=j[i-1]?+a?i?`
CIA: `:`CIA: `:`
BANE: `:``)+(+a?b:c).shift()).join` `

용법

f=n=>[...n.toString(2,b="If I pull that off will you die? You're a big guy.".split` `,c="It would be extremely painful... for you!".split` `)].map((a,i,j)=>(a!=j[i-1]?+a?i?`
CIA: `:`CIA: `:`
BANE: `:``)+(+a?b:c).shift()).join` `
f(522300)

노트

이것은 진행중인 골프입니다. 나는 여전히 약간의 바이트를 면도 할 수 있다고 생각하지만 의견에 제안을 남겨 두십시오.


4

파이썬 3.6, 232 바이트

from itertools import*
c="you! for painful... extremely be would It".split(),"guy. big a You're die? you will off that pull I If".split()
for n,r in groupby(f'{int(input()):b}',int):
 print("BCAINAE::"[n::2],*[c[n].pop()for _ in r])

동등하게 편집하십시오 .

from itertools import*
c="It would be extremely painful... for you!".split(),"_ If I pull that off will you die? You're a big guy.".split()
for n,r in groupby(map(int,f'{int(input()):b}')):
 print("BCAINAE::"[n::2],*map(c[n].pop,r))

3

apt, 121 바이트

A=[`It Ùd ¼ extÚ+ pafª... f y!`¸`If I pªl È     f Øi y ¹e? Y' a big guy.`¸]¢®^T?["
BANE:""
CIA:"]gT=Z :P +S+AgZ vÃx

인쇄 할 수없는 항목이 많이 있으므로 온라인 에서 테스트하는 것이 좋습니다 .


2

펄 6 , 211 바이트

{.put for map |*,zip map {.[0]X .[1].rotor: .[2..*]},zip <CIA: BANE:>,(<If I pull that off will you die? You're a big guy.>,<It would be extremely painful... for you!>),|(.base(2)~~m:g/(.)$0*/)».chars.rotor(2)}

2

C #을 398 390 385 396 389 바이트

class P{static void Main(string[] a){string s="2"+System.Convert.ToString(int.Parse(a[0]),2),e="CIA: ",r="BANE: ",o="";int k=0,l=0,i=1;string[] c="If I pull that off will you die? You're a big guy.".Split(' '),b="It would be extremely painful... for you!".Split(' ');for(;i<s.Length;i++)o+=(s[i-1]==s[i]?" ":(i<2?"":"\n")+(s[i]>'0'?e:r))+(s[i]>'0'?c[k++]:b[l++]);System.Console.Write(o);}}

입력 번호를 매개 변수로 사용하여 시작하십시오.

언 골프 드 :

class P
{
    static void Main(string[] a)
    {
        string s = "2" + System.Convert.ToString(int.Parse(a[0]), 2), e = "CIA: ", r = "BANE: ", o = "";
        int k = 0, l = 0, i = 1;

        string[] c = "If I pull that off will you die? You're a big guy.".Split(' '), b = "It would be extremely painful... for you!".Split(' ');
        for (; i < s.Length; i++)
            o += (s[i - 1] == s[i] ? " " : (i<2?"":"\n") + (s[i] > '0' ? e : r))
                + (s[i] > '0' ? c[k++] : b[l++]);
        System.Console.Write(o); 
    }
}

"시작시 줄 바꿈 없음"규칙을 알지 못했기 때문에 396 바이트로 돌아갑니다.


슬프게도 s.Replace("1",c[k++]).Replace("0",b[l++])해당 단어로 대체되지 않습니다. C #은 문자열을 한 번 바꾸고 장소에서 때리는 것 같습니다.
Mr Scapegrace

2

루비, 204 + 1 = 205 바이트

-n깃발이 필요합니다 .

d=[%w"It would be extremely painful... for you!",%w"If I pull that off will you die? You're a big guy."]
n=%w"BANE CIA"
("%b"%$_).scan(/((.)\2*)/).map{|i,b|puts n[k=b.to_i]+': '+d[k].slice!(0,i.size)*' '}

2

PHP, 198 바이트

while($i++<19)echo($t-$s=1&$argv[1]>>19-$i)?"
"[$i<2].($s?CIA:BANE).": ":" ",explode(0,"It0would0be0extremely0painful...0for0you!0If0I0pull0that0off0will0you0die?0You're0a0big0guy.")[$$s+++7*$t=$s];

1

펄, 205 바이트

@t=([qw/It would be extremely painful... for you!/],[qw/If I pull that off will you die? You're a big guy./]);$_=sprintf'%b',$0;print$n?'BANE':'CIA',": @{[splice$t[$n=1-$n],0,length$&]}"while s/(.)\1*//;

이 파일을 494542라는 파일에 넣고 다음과 같이 실행하십시오.

perl -lX 494542

Perl v5.22에서 테스트


1

클로저, 401 바이트

(require '[clojure.string :as s])(defn f[n](let[c(map #(-(int %) 48)(Integer/toString n 2))p[(s/split"It would be extremely painful... for you!"#" ")(s/split"If I pull that off will you die? You're a big guy."#" ")]a["BANE" "CIA"]](loop[i[0 0] g"" d c q 2](if(<(count d)1)g(let[b(first d)j(i b)](recur(assoc i b (inc j))(str g(if(= b q)" "(str(when(not= 2 q)"\n")(a b)": "))((p b) j))(rest d) b))))))

기도:

(f 522300)

언 골프

(require '[clojure.string :as s])
(defn dialogue[num]
    (let [dacode (map #(- (int %) 48) (Integer/toString num 2))
          phrases [(s/split"It would be extremely painful... for you!"#" ")(s/split"If I pull that off will you die? You're a big guy."#" ")]
      actors ["BANE" "CIA"]]
      (loop [idxs [0 0] finaldial "" code dacode prevbit 2]
        (if (< (count code) 1) finaldial
            (let [bit (first code) idx (idxs bit)]
              (recur (assoc idxs bit (inc idx)) (str finaldial (if (= bit prevbit) " " (str (when (not= 2 prevbit) "\n") (actors bit) ": ")) ((phrases bit) idx)) (rest code) bit))))))
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.