怒りのカモ


56

絵文字>:Uが何を表しているのか、誰もはっきりとはわかりませんが、多くの学者は、それが怒っているアヒルのように見えると信じています。そうだと仮定しましょう。

仕事

0から3までの整数nが与えられた場合、印刷またはリターン

quack

n = 0の場合、

>:U

もし、N = 1、

     U   U
>  : U   U
 >   U   U
>  : U   U
      UUU

n = 2の場合、または

                  >:U         >:U
>:U               >:U         >:U
   >:U       >:U  >:U         >:U
      >:U         >:U         >:U
         >:U      >:U         >:U
      >:U         >:U         >:U
   >:U       >:U  >:U         >:U
>:U               >:U         >:U
                     >:U>:U>:U

n = 3の場合

入力は常に有効であると想定できます。出力に先行スペースはないはずですが、後続スペースはいくらでも問題ありません。アヒル(@cobaltduckを除く)は、抜け穴に対する耐性がありません。バイト単位の最短コードが優先されます。


90
最初に、「あぁ、アヒルとは何ですか?」と考えていました。幸いなことに、ウィキペディアのページへのリンクを提供しました。
アドナン

6
「アヒルには抜け穴に対する耐性がありません。」しかし、あなたはアヒルではなく鳥です、それは抜け穴を使用できるということですか?:P-
ダウンゴート

6
@Downgoatいや。また、その編集はまったく不要だったので、ロールバックしました。
アレックスA.

6
@Downgoat s /:P />:U /
ETHproductions

7
「アヒルには抜け穴に対する耐性がありません。」それは私の友人、危険なステレオタイプです。私はあなたの意図を知らなかった場合、私は罪を犯すかもしれません。
コバルトダック

回答:


19

CJam、108 90 85バイト

"quack"">:U":D"scT¦{$ì"{269b22bSf*D}:F~[ZYB].*s.+s5/"ÿ3nÜïS{JÐø¦yûn"F*33/z]ri=zN*

一部の文字は印刷できないことに注意してください。オンラインでお試しください!

バックグラウンド

最初の2つの出力は、CJamでは圧縮できません。

最後の出力の圧縮は簡単です。すべての改行を削除した後、結果の文字列をの発生時に分割し、結果>:Uの各文字列の長さを計算できます。

結果は配列になります

[18 9 0 15 9 3 7 2 9 6 9 9 9 6 9 6 9 9 3 7 2 9 0 15 9 21 0 0 0]

基数22から基数269に変換することで効率的に保存でき、数字が得られます

[255 12 51 110 220 239 83 123 74 208 248 166 121 251 110 17]

各桁は256未満なので、1バイトとして格納できます。

最後に、行と列を転置すると、3番目の出力の圧縮が容易になります。

 > > 
  >  

 : : 

UUUU 
    U
    U
    U
UUUU

非空白文字間のスペースをもう一度カウントすると、配列が得られます

[1 1 3 8 1 6 0 0 0 5 4 4 0 0 0 0 0]

になる

[115 159 99 84 166 123 36 236 6]

ベース22からベース269にトランスコードされた場合。

使い方

"quack"   e# Push the first output.

">:U":D   e# Push the second output, and save it in D.

e# Push [115 159 99 84 166 123 36 236 6] as bytes.

"scT¦{$ì"

{         e# Define a code block:
  269b22b e#   Transcode from base 269 to base 22.
  Sf*     e#   Replace each digit with a string of that many spaces.
  D       e#   Push D.
}         e#
:F~       e# Save the block in F. Execute it.
[ZYB]     e# Push [3 2 11].
.*        e# Vectorized repeat; push [">>>" "::" "UUUUUUUUUUU"].
s         e# Flatten the array of strings.
.+        e# Append the nth character to the nth string of spaces.
s5/       e# Flatten and split into chunks of length 5.

e# Push [255 12 51 110 220 239 83 123 74 208 248 166 121 251 110 17] as bytes.

"ÿ3nÜïS{JÐø¦yûn"

F         e# Execute F.
*         e# Join the resulting array of strings of spaces, separating by ">:U".
33/       e# Split into chunks of length 33.
z         e# Zip; transpose rows with columns.

]         e# Wrap the entire stack in an array.
ri        e# Read a token from STDIN and interpret it as an integer.
=         e# Retrieve the element at the corresponding index.
z         e# Zip; transpose rows with columns or map "string" to ["string"].
N*        e# Join, separating by linefeeds.

2
:Dは2つの文字列の間の余分が好きです。
ズガルブ

7
@Zgarb彼は偉大なカモの君主をなだめました。アヒルは笑顔になりました。
アレックスA.

7
「172 ... 162 ... 182 ...私はそれらすべてを打ち負かすことができます。待ってください、90?ああ、それは無敵のデニスです...」
ETHproductions

22

Java、303 286バイト

@VoteToCloseのおかげで17バイトを節約できました!

実際に最短になることを意図したものではなく、Javaで試してみるのは楽しいと思いました。

共通の文字列を表す文字列変数のリストを作成し、すべての出力の配列を作成してから、正しい出力を出力します。

String a(int y){String n="\n",d=">:U",A=" ",B=A+A,C=B+B,D=C+C,a="U"+B+" U"+n,G=D+A,H=C+B,c=d+G+d+n,E=B+A,F=C+E;String[]z={"quack",d,C+A+a+">"+B+": "+a+" >"+E+a+">"+B+": "+a+C+B+"UUU",D+D+B+c+d+D+F+c+B+A+d+F+d+B+c+H+d+G+c+G+d+H+c+H+d+G+c+E+d+F+d+B+c+d+D+F+c+D+D+C+A+d+d+d};return z[y];}

ゴルフをしていない:

String a(int y) {
    String n = "\n", d = ">:U", A = " ", B = A + A, C = B + B, D = C + C,
            a = "U" + B + " U" + n, G = D + A, H = C + B, c = d + G + d + n,
            E = B + A, F = C + E;
    String[] z = { "quack", d, C + A + a + ">" + B + ": " + a + " >" + E + a + ">" + B + ": " + a + C + B + "UUU", D + D + B + c + d + D + F + c + B + A + d + F + d + B + c + H + d + G + c + G + d + H + c + H + d + G + c + E + d + F + d + B + c + d + D + F + c + D + D + C + A + d + d + d };
    return z[y];
}

これがこのサイトでの最初の回答ですので、何か間違ったことをした場合は教えてください。


2
元気そう!素敵な最初の投稿、PPCGへようこそ!
コナーオブライエン

@AlexA。私に知らせてくれてありがとう、私はそれを修正しました。
FlyingPiMonster

2
@ kittycat3141素晴らしく見える。素敵な解決策と私の挑戦に参加してくれてありがとう!:)
アレックスA.

それはそれを表示されますD+Aと、C+B2つの新しい変数にさらにgolfedするために十分な頻度で表示されます。また、私は役立つかもしれないforループで配列を使用していることを少しでも感覚を得るが、私はどのように、まだ考え出したていない...
アディソンCrumpの

9

05AB1E162 159 157バイト

コード

くそー、長すぎるが、少なくとも何か:

">:U"VI3Qið16×7166b1ð:0Y:DUJ,Yð13×JD?X,3838b1ð:0Y:D?X,16255b1ð:0Y:D?X,16367b1ð:0Y:4F?X,}ð21×Y3×J,}¹2Qið4×" U   U"©J,">  :"®JD," >  "?®,,ð6×'U3×J,}¹iY,}"quack

オンラインでお試しください!


説明

コードの最初の部分はに存在し">:U"VYその文字列に設定されます。その後、入力が3に等しいかどうかを確認するだけです。I3Qi部分でます。等しい場合、巨大なカササギを印刷します。

N = 3

最初に、ð16×16個のスペース文字をプッシュします。その後、番号があり7166bます。これは、">:U "Retinaから少し助けを借りて、この部分をカバーしています:)。私が使用このスクリプトをバイナリ文字列を数値に変換すること。その後、1ð:0Y:パーツに到達します。これにより、1すべて0がスペース文字に置き換えられ、すべてYがに設定され>:Uます。その後、我々はD、この文字列をuplicateに格納しX使用UしてJスタックOIN。を使用してこれをポップ,します。これにより、完全な文字列が改行で出力されます。それ以降のすべては、すべて同じ原則に基づいています。ifステートメントは2番目で終了し}ます。

完全な変換については、こちらをご覧ください

N = 2

ここで、入力が2に等しいかどうかを確認します。これはデバイスで行われ¹2Qiます。その後、等しい場合、を使用してスペース文字を4回プッシュしð4×ます。その後、" U U"文字列をプッシュして保存します©(Jellyから露骨に盗まれたアイデア:p)。Jスタックを再びoinし、これを改行で印刷します。その後、"> :"文字列をプッシュし、スタック内でusing " U U"を取得し®、この文字列を複製して、両方を同じ行に出力します。JD

短いクイズ、これは何をします" > "?®,か?

上記の文字列を印刷した後、面の2行目の複製を取得し、これを印刷します(2行目と同じであるため)。

このケースの最後の部分は次のとおりです。

ð6×'U3×J,

ð6×        # Push the space character × 6
   'U3×    # Push the "U" character three times
       J,  # Join and print pop with a newline

N = 1

これは説明が簡単です:

¹1QiY

¹1Qi   # Check if the input is equal to 1
    Y  # Push the magpie face
       # This is then implicitly printed

N = 0

¹0Qi"quack

¹0Qi        # Check if the input is equal to 0
    "quack  # Weird sound what magpies make
            # Implicitly printed

説明plz?:P
アディソンクランプ

@VoteToClose完了:)
アドナン

「長すぎる」?私の答えを参照してください:-P
ルイスメンドー

2
カササギをカササギするTIL。どうやら。
アレックスA.

8

Vitsy172の 171 159バイト

ああ、そうだ。メソッドの威力を誇示するものが欲しければ、それを手に入れました。

' 'V1+m
'kcauq'Z
'U:>'Z
58m5m6m'   > 'Z5m6m'UUU'68m
f3+bm9mamcm98m2m6bmcmam9mf6+8m3\[2m]
a'U   U'Z
' :  >'Z5m
Z2m98ma2m
\VZ
2mfbm
VVVZ2m78m2mVV7m
8m7m
68m2m9bm

オンラインでお試しください!

これがどのように機能するかは、それ自体でさまざまなメソッドを呼び出すことです。説明は以下のとおりです。

' 'V1+m
' 'V      Save character literal ' ' as a permanent variable.
    1+    Add one to the top item of the stack (input + 1)
      m   Go to that index of code.

'kcauq'Z
'kcauq'   Push 'quack' to the stack.
       Z  Output everything in the stack as a char.

'U:>'Z
'U:>'Z    Ouput ">:U" with the same method as the previous line.

Now on to some more... interesting lines.

58m5m6m'   > 'Z5m6m'UUU'68m
5              Push space, push 4
 8m            Call the 8th line index.
               As we will soon see, the 8th line index duplicates the space
               the number of times specified by the number just before the call 
               (4 in this case)
   5m          Call the 5th line index.
               The 5th line index outputs the 'U   U' and a newline.
     6m        Call the 6th line index.
               The 6th line index outputs '>  : U   U' and a newline.
'   > 'Z       Output ' >   '.
        5m6m   Same method calls as before.
'UUU'          Push 'UUU'.
     68m       Push 6, then call the 8th line index. This gives us the correct padding.

f3+bm9mamcm98m2m6bmcmam9mf6+8m3\[2m]
f3+              Push 18.
   bm            Call the 11th line index.
                 The 11th line index calls the 8th line index (which we've already seen
                 in action) and then the 7th line index, which you can find and explanation
                 for below (it does a lot)
     9m          Call the 9th line index.
                 The 9th line index outputs '>:U               >:U         >:U' (explanation lower)
       am        Call the 10th line index.
                 ...I'm gonna stop explaining these and just tell you to go to the lines now. :P
         cm      Call the 12th line index.
9                Push space, push 9.
 8m              Call the 8th line index (explained below and before).
   2m            Call the 2nd line index.
     6           Push 6.
      bm         Call the 11th line index. We've finished up to '>:U      >:U         >:U' now.
cm               You guessed it! Call the 12th line index. (explanation below)
  am             Call the 10th line index. (explanation below)
    9m           Call the 9th line index. (explanation below)
f6+              Push space, push 19 21.
   8m            Call the 8th line index. (explanation below)
     3\[2m]      Call the 2nd line index thrice.

All of the rest of these methods are supporting methods now.

a'U   U'Z       Output 'U   U' followed by a newline.

' :  >'Z5m      Output '>  : U   U' followed by a newline.

Z2m98ma2m
Z               Output everything currently in the stack.
 2m             Call the 2nd line index.
   9            Push space, push 8.
    8m          Call the 8th line index. (explained below)
      a         Push a newline to the stack.
       2m       Call the 2nd line index.
                This handles the biggest angry duck face's faces showing the eyebrows and eyes.

\VZ
\V    Push space as many times as the top item specifies.
  Z   Output everything in the stack.

2mfbm
2m      Call the 2nd line index.
  f     Push space, push 14.
   bm   Go to the 11th line index.
        This handles the mouth and some parts of the eyebrows of the biggest duck face.

VVVZ2m78m2mVV7m
VVVZ              Output 3 spaces (and whatever was pushed before it)
    2m            Call the 2nd line index.
      7           Push space, push 6.
       8m         Call the 8th line index. (explained... above)
         2m       Call the 2nd line index.
           VV     Push 2 spaces.
             7m   Call the 7th line index.

8m7m     This is pretty damn self-explanatory if you've read this far.

68m2m9bm
6            Push space, push 5.
 8m          Call the 8th line index.
   2m        Call the 2nd line index.
     9       Push space, push 9.
      bm     Call the 11th line index.

このコードはばかげています。詳細形式は次のとおりです。

toggle single quote;
 ;
toggle single quote;
save top as permanent variable;
push 1;
add top two;
goto top method;
:toggle single quote;
k;
push 12;
push 10;
flatten top two stacks;
q;
toggle single quote;
output stack as chars;
:toggle single quote;
U;
clone current stack;
go forward;
toggle single quote;
output stack as chars;
:push 5;
push 8;
goto top method;
push 5;
goto top method;
push 6;
goto top method;
toggle single quote;
 ;
 ;
 ;
go forward;
 ;
toggle single quote;
output stack as chars;
push 5;
goto top method;
push 6;
goto top method;
toggle single quote;
U;
U;
U;
toggle single quote;
push 6;
push 8;
goto top method;
:push 15;
push 3;
add top two;
push 11;
goto top method;
push 9;
goto top method;
push 10;
goto top method;
push 12;
goto top method;
push 9;
push 8;
goto top method;
push 2;
goto top method;
push 6;
push 11;
goto top method;
push 12;
goto top method;
push 10;
goto top method;
push 9;
goto top method;
push 15;
push 6;
add top two;
push 8;
goto top method;
push 3;
repeat next instruction set top times;
begin recursive area;
push 2;
goto top method;
end recursive area;
:push 10;
toggle single quote;
U;
 ;
 ;
 ;
U;
toggle single quote;
output stack as chars;
:toggle single quote;
 ;
clone current stack;
 ;
 ;
go forward;
toggle single quote;
output stack as chars;
push 5;
goto top method;
:output stack as chars;
push 2;
goto top method;
push 9;
push 8;
goto top method;
push 10;
push 2;
goto top method;
:repeat next instruction set top times;
save top as permanent variable;
output stack as chars;
:push 2;
goto top method;
push 15;
push 11;
goto top method;
:save top as permanent variable;
save top as permanent variable;
save top as permanent variable;
output stack as chars;
push 2;
goto top method;
push 7;
push 8;
goto top method;
push 2;
goto top method;
save top as permanent variable;
save top as permanent variable;
push 7;
goto top method;
:push 8;
goto top method;
push 7;
goto top method;
:push 6;
push 8;
goto top method;
push 2;
goto top method;
push 9;
push 11;
goto top method;

7

JavaScript(ES6)、163バイト

var solution =

n=>["quack",d=">:U",`5U3U
>2:1U3U
1>3U3U
>2:1U3U
6UUU`,`99090
096090
30702090
609090
906090
609090
30702090
096090
993000`][n].replace(/\d/g,c=>+c?" ".repeat(c):d)
<input type="number" oninput="R.textContent=solution(+this.value)"><pre id="R"></pre>

説明

JavaScriptで実行中の圧縮(ランレングスエンコーディング)を使用します。その数のスペースにマップする数字、怒っているアヒルの顔19マップする数字0、およびその他のキャラクターは同じままです。


1
ゴルフ以外の言語では非常に印象的ですが、n = 3の中央の上下の行が欠落しているようです。
ETHproductions

@ETHproductionsおっと、そこで何が起こったのかわかりません。修正されました。
user81655

7

JAPT、116の 105 102 99 96バイト

["quack""c)`+«öÂ[@=^Gñ`1]o2"mc r'4#¿+R "4z>2:z >2z>2:z6UUU"rz" U3U
" '1]®r'1">:U" r"%d"_SpZ}ÃgU

印刷できないものが含まれています。オンラインでテストしてください!

使い方

最初の2つの文字列はまったく圧縮されていません。第三は、次いで、その長とスペースの各ランを置き換えることによって単純に圧縮される" U3U""z"。最後のものはより複雑です:

  1. 2〜9個のスペースの各ランをその長さに置き換えます。
  2. 交換してください>:U1
  3. 交換してください191\n4。(4文字列の他の場所では使用されません。)
  4. 有効な各バイトコード(10- 255、または0A- FF)をその文字コードを持つ文字にマップします。

結果の文字列の長さは21 19バイトのみですが、解凍にはさらに31 29が必要です。

文字列を圧縮解除した後U、入力位置であるアイテムを取得します。(配列が配列され[0,3,2,1]ているのは、配列の先頭ではなく末尾からカウントするバグがあるためです。)

[                      // Create an array of the following:
  "quack"              //  "quack".

  "c)`+«öÂ[@=^Gñ`1]o2" //  Take this string (contains an unprintable).
                       //  Map each char to its char code.
                       //  This produces "994196431712461949164619431712419649931112".
  r'4#¿+R              //  Replace each "4" with the char code of "¿" (191) + a newline.

  "4z>2:z >2z>2:z6UUU" //  Take this string.
  rz" U3U\n"           //  Replace each "z" with " U3U\n".

  '1                   //  "1".
]
®              Ã       // Map each item by this function:
r'1">:U"               //  Replace each "1" with ">:U".
r"%d"_SpZ}             //  Replace each remaining digit Z with Z spaces.

gU                     // Get the item at index -U, wrapping. 
                       // (This should just be U, but there's a bug which negates it.)

5

MATL283 182バイト

@Adnanのおかげで101バイトが節約されました!

これは10進数を使用してインデックスをエンコードします0... 3ケース2および3の4文字に10進数は、おそらくbase-64エンコードを使用して圧縮できますが、変です!

ケース3について@Adnanによって示唆非常に素晴らしいトリックが使用される:ここで、各列を符号化するために、バイナリシーケンスを定義0し、1空間に対応して>:U夫々 。

~?'quack'}G1=?'>:U'}G2=?' :>U'12336 8466480h2109488h8466480h4032h4YA47-)}268697600 67174401h16795656h67174464h67174912h67174464h16795656h67174401h14680064h"@BP48+]Xh49'>:U'YX48 32YXc

オンラインでお試しください!


3
どのように最後のケースでは約、使用してこれを交換し、1スペースとを0持つ>:U文字列。それが役立つかどうかはわかりません。
アドナン

@Adnanそれは良いアイデアです!
ルイスメンドー

5
-O:保存された101バイト@Adnan
ルイスMendo

すごい!とてもいい答えです!:)
アドナン

5

シナモンガム、76バイト

0000000: 6c33 502b 2c4d 4cce b636 54b3 b30a b536  l3P+,ML..6T....6
0000010: 5253 0081 5010 e6b2 5350 b082 3215 ecb0  RS..P...SP..2...
0000020: 8a42 1487 865a 1bab 2960 00a0 79c8 6c2e  .B...Z..)`..y.l.
0000030: 2026 a002 4221 0430 55c0 5938 cd40 9720   &..B!.0U.Y8.@. 
0000040: 6c06 6177 90e9 17ac 4102 4100            l.aw....A.A.

シナモンガムはこのチャレンジ後に作成されたため、競合しません。

オンラインでお試しください。

説明

最初のバイトlはモードを指定します。この場合、Cinnamon Gumにルックアップテーブルモードに入るように指示します。シナモンガムは、残りの文字列(で圧縮されているzopfli --deflate)を次のように解凍します。

0&quack;1&>:U;2&     U   U
>  : U   U
 >   U   U
>  : U   U
      UUU;3&                  >:U         >:U
>:U               >:U         >:U
   >:U       >:U  >:U         >:U
      >:U         >:U         >:U
         >:U      >:U         >:U
      >:U         >:U         >:U
   >:U       >:U  >:U         >:U
>:U               >:U         >:U
                     >:U>:U>:U

次に、で分割し;、各キーと値のペア(&区切り文字として)を辞書に入れて、を出力しますdictionary[input]


5

JavaScriptのES6、232の 223 203 188バイト

保存された29 ETHproductionsに44バイトのおかげ!

n=>[`quack`,r=`>:U`,`     U   U
>  : U   U
 >   U   U
>  : U   U
      UUU`,`00022
10022
0100 1  12
00122
20012
00122
0100 1  12
10022
0000211`.replace(/\d/g,N=>[g=`   `,r,g+g+g+r][N])][n]

試してみてください!


確かにそれはatob'dすることができます...そうでない場合は、 1 andを3 0進数にすることができますか?
ダウンゴート

1
@Downgoat btoaingとtrinaryはどちらも長いです。
コナーオブライエン

古い答えですが、それに応じて文字列に変更r+g+g+g+rg+g+g+rて調整することで、15バイトほど節約できます。
-ETHproductions

0

GML、265バイト

@ kittycat3141の優れた回答の移植版で、@ VoteToCloseによる2つの新しい変数(私はGとHと名付けました)でさらにゴルフすることを提案しています。また、GMLの比較的緩やかな構文を使用して、さらに短縮することもできました。

d=">:U"A=" "B=A+A;C=B+B;D=C+C;G=D+A;H=C+B;a="U"+B+" U"+"#"c=d+G+d+"#"E=B+A;F=C+E;x[0]="quack"x[1]=d;x[2]=C+A+a+">"+B+": "+a+" >"+E+a+">"+B+": "+a+H+"UUU"x[3]=D+D+B+c+d+D+F+c+B+A+d+F+d+B+c+H+d+G+c+G+d+H+c+H+d+G+c+E+d+F+d+B+c+d+D+F+c+D+D+C+A+d+d+d;return x[argument0]
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.