Großer Code ... für Sie!

32

In der Eröffnungsszene des Dark Knight kommt es zu einem eher unangenehmen Dialog zwischen einem CIA-Agenten und dem Bösewicht Bane.

CIA-Agent: "Wenn ich diese [Maske] abhebe, wirst du sterben?"

Bane: "Es wäre extrem schmerzhaft ..."

CIA-Agent: "Du bist ein großer Kerl."

Bane: "... für dich."

Es ist nicht sicher, ob Bane vorhat, "schmerzhaft für dich" oder "großer Kerl für dich" zu sagen. Lassen Sie uns dieses Problem ein für alle Mal durch Code-Golfen lösen!

Herausforderung

Ihre Aufgabe ist es, ein Programm zu schreiben, das den obigen Dialog in Abhängigkeit von einer als Eingabe angegebenen Ganzzahl neu anordnet.

CIA-Agentendialogwörter sind: If I pull that off will you die? You're a big guy.

Banes Dialogwörter sind: It would be extremely painful... for you!

Bitte beachten Sie, dass die?, You’re, painful...und you!werden als einzelne Wörter betrachtet.

  1. Konvertieren Sie eine Ganzzahl n als Eingabe in eine Binärzahl
  2. Lesen Sie die Binärziffern von links nach rechts und geben Sie das nächste Wort aus dem CIA-Agentendialog aus, wenn es sich um die Ziffer handelt 1, und das nächste Wort aus dem Bane-Dialog, wenn es sich um die Ziffer handelt 0. Die Wörter sollten durch ein Leerzeichen getrennt sein. Wenn sich der Lautsprecher ändert, fügen Sie einen Zeilenvorschub hinzu. Stellen Sie außerdem jeder Dialogzeile den Sprechernamen ( BANE:oder CIA:) voran.

Sie können davon ausgehen, dass die Eingabe immer mit einer 1 in binärer Form beginnt und 12 Einsen und 7 Nullen hat.

Beispiel

522300

  1. Umgerechnet in binär: 1111111100000111100

  2. Die Zahl beginnt mit 8, daher geben wir die 8 ersten Wörter aus dem Agentendialog der CIA aus und stellen ihnen CIA voran: CIA: If I pull that off will you die?

  3. Dann haben wir 5 Nullen, also bekommen wir die 5 ersten Wörter aus Banes Dialog: BANE: It would be extremely painful...

  4. Dann gibt es 4, also geben wir die 4 nächsten CIA-Wörter aus: CIA: You’re a big guy.

  5. Dann 2 Nullen: BANE: for you!

Endergebnis:

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

Weitere Testfälle:

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.
Arnaud
quelle
Kann jede Zeile in einem Leerzeichen enden?
Xnor
@xnor Ja, das ist in Ordnung.
Arnaud
"das" und "es" als erstes Wort von
Banes
@Mistah fixiert auf "es", danke!
Arnaud
3
Ist es nur ich oder jemand, der den Dialog mit Banes Stimme liest?
Gurupad Mamadapur

Antworten:

10

Pyth - 138 Bytes

Ich sollte mich mit dem Komprimieren des Filmskripts befassen.

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

Test Suite .

Maltysen
quelle
7

JavaScript (ES6), 203 bis 201 Byte

Edit: 2 Bytes gespart durch schamloses Ausleihen der trim()Idee von ETHproductions Antwort

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

Testfälle

Arnauld
quelle
7

JavaScript (ES6), 209 202 201 Byte

(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())``

Alter Ansatz:

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

Testschnipsel

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

ETHproductions
quelle
Ich leihe mir deine trim()Idee schamlos aus . Ich war mir sicher, dass es etwas Besseres gab slice(1), konnte es aber nicht herausfinden.
Arnauld
@Arnauld Gut mit mir, jetzt sind wir alle gefesselt. Ich wette, es gibt eine Möglichkeit, dies in unter 200 zu tun :-)
ETHproductions
6

C ++ 11 (GCC), 298 293 Bytes

#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;}

Eine Lambda-Funktion, die eine Ganzzahl annimmt und den Dialog als zurückgibt std::string. Sie können es hier in Aktion sehen .

Ungolfed Version (mit einer Erklärung):

#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;
}
Vaultah
quelle
4

JavaScript (ES6), 252 227 226 Byte

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

Verwendung

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)

Anmerkungen

Ich denke, ich kann noch einige Bytes abschneiden, kann aber gerne Vorschläge in den Kommentaren hinterlassen.

Luke
quelle
4

Python 3.6, 232 Bytes

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

Äquivalent bearbeiten :

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))
Orez
quelle
3

Japt, 121 Bytes

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

Enthält viele nicht druckbare Dateien, daher sollten Sie diese besser online testen .

ETHproductions
quelle
2

Perl 6 , 211 Bytes

{.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)}
smls
quelle
2

C #, 398 390 385 396 389 Bytes

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);}}

Starten Sie mit der eingegebenen Nummer als Parameter.

Ungolfed:

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); 
    }
}

Zurück zu 396 Bytes, weil ich die Regel "Keine Zeilenumbrüche am Anfang" nicht bemerkt habe.

Herr Scapegrace
quelle
Ersetzt s.Replace("1",c[k++]).Replace("0",b[l++])leider nicht durch entsprechende Wörter. Es sieht so aus, als würde C # die Zeichenkette einmal ersetzen und sie stellenweise schlagen.
Mr Scapegrace
2

Ruby, 204 + 1 = 205 Bytes

Benötigt die -nFlagge.

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)*' '}
Wert Tinte
quelle
2

PHP, 198 Bytes

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];
user63956
quelle
1

Perl, 205 Bytes

@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*//;

Fügen Sie das in eine Datei mit dem Namen 494542 ein und führen Sie Folgendes aus:

perl -lX 494542

Getestet auf Perl v5.22

Kjetil S.
quelle
1

Clojure, 401 Bytes

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

Aufruf:

(f 522300)

Ungolfed

(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))))))
Attilio
quelle