アヒル、アヒル、消えた!


40

これは(非常に怖い)5つの小さなアヒルの歌です(長くはありません):

Five little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only four little ducks came back.

Four little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only three little ducks came back.

Three little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only two little ducks came back.

Two little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only one little duck came back.

One little duck went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but none of the little ducks came back.

Mother duck herself went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
and all of the little ducks came back.

あなたの仕事はこの歌を出力することではありません。詩を取り、次の詩を出力する必要があります(最後の詩の次の詩が最初の詩です)。

ルール

  • 標準的な抜け穴はありません。
  • 入出力は、標準の入出力メソッドを介して取得されます。
  • 正確な詩が出力されなければならない、と曲の歌詞と比較して有意差があってはなりません。入力は、歌の歌詞と比較しても変わりません。

Mother duck herself went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
and all of the little ducks came back.

期待される:

Five little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only four little ducks came back.

Three little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only two little ducks came back.

期待される:

Two little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only one little duck came back.

22
私が若かった頃、多くの月前に、これに対する言葉がわずかに異なっていたことを覚えています。しかし、それによって心的外傷を受けたことも覚えています!当時、行方不明になったアヒルの子はどこにいましたか?!なぜ彼らを探していないのですか?!そして、どんな種類の無責任な母親がどうしてそんなに多くの子供たちを失い、残りの子供たちを遊ばせ続けているのでしょうか?!ホラー!
シャギー

8
重複する可能性があります。冗談です:)
Night2

7
あなたは私を石化しただけです。
A _

2
その歌の歌詞は、私に感情のジェットコースターを通過させました。
Num Lock

2
昨日ここで投稿したYouTubeビデオを2回、2回だけ聴きました。歌は私の脳に埋め込まれ、どこへ行っても、何をしても、聞こえ続けます!ヘルプ...
夜2

回答:


3

スタックス115 111 バイト

τ*^&k─Zè0µ9┬$█◘çl╟☼:Drσ59ò╠▄┴╢Q♂╔¡ô╜Oa╣▀yèA÷╨%^♀█Ö+╡◄ì=∙%╧o▌Θ<▲Çα¿╗√;1°┼╤V◘ú┐♥▒ÇM☼b╩░o]YaL4░ƒ%(Æ♫Q0æÆä⌂¡╘○Eâó╪¡

実行してデバッグする

テストケースとしてのすべての詩


1
「1つの小さなアヒル」で実行すると、「小さなアヒルの小さなアヒルと小さなアヒルが戻ってきた」と応答します。最後の行。
ドリアン

1
このバグは、サイズが無料で修正されました。実際には2バイトのコストであり、他の場所で2バイトの節約を相殺しましたが、ここでバイトを測定するのは少し難しいですが、変更は圧縮された文字列リテラル内、または最終的なプログラム内でも正確にバイト調整されていません。
再帰的

19

JavaScript(ES9)、227バイト

これは、以下のNodeバージョンに似ていますが、入力詩を識別するparseInt()代わりに基づいた式を使用しBuffer()ます。

これはES2018(別名ES9)です。これは、/sフラグ(dotAll)を含む正規表現を使用しているためです。

s=>'Mother duck herself1and all23,,Three4two3,Five4four3,Four4three3,One01but none23,Two4one0'.split`,`[parseInt(s,30)&7].replace(/\d/g,n=>[x=' little duck',y=/ w.*\n/s.exec(s),' of the',x+='s',x+y+'but only '][n])+s.slice(-11)

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

どうやって?

このバージョンでは、我々は、ベース30(として全入力詩を解析0するt)とビット単位で実行し、7で解析がにつながる、最初の無効な文字の上に停止します。

 verse | valid part | base 30 -> decimal | AND 7
-------+------------+--------------------+-------
   0   |  'fi'      |            468     |   4
   1   |  'fo'      |            474     |   2
   2   |  'three'   |       23973734     |   6
   3   |  't'       |             29     |   5
   4   |  'one'     |          22304     |   0
   5   |  'mother'  |      554838747     |   3

JavaScript(Node.js) 233 231  227バイト

@Shaggyのおかげで2バイト節約

s=>'Three4two3,Four4three3,Mother duck herself1and all23,One01but none23,,,Two4one0,,Five4four3'.split`,`[Buffer(s)[2]%9].replace(/\d/g,n=>[x=' little duck',y=/ w.*\n/s.exec(s),' of the',x+='s',x+y+'but only '][n])+s.slice(-11)

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

どうやって?

各入力詩の3番目の文字は、一意の識別子として使用できます。9を法とするASCIIコードを取得すると、次のようになります。

 verse | 3rd char. | ASCII code | MOD 9
-------+-----------+------------+-------
   0   |    'v'    |     118    |   1
   1   |    'u'    |     117    |   0
   2   |    'r'    |     114    |   6
   3   |    'o'    |     111    |   3
   4   |    'e'    |     101    |   2
   5   |    't'    |     116    |   8

出力の詩は、次のテンプレートでエンコードされます。

 verse | template
-------+---------------------------------
   0   | 'Five4four3'
   1   | 'Four4three3'
   2   | 'Three4two3'
   3   | 'Two4one0'
   4   | 'One01but none23'
   5   | 'Mother duck herself1and all23'

各数字は、次の表に従って文字列に置き換えられます。

 digit | replaced with
-------+---------------------------------------------------
   0   | ' little duck'
   1   | / w.*\n/s.exec(s)
   2   | ' of the'
   3   | ' little ducks'
   4   | ' little ducks' + / w.*\n/s.exec(s) + 'but only '

正規表現/ w.*\n/sが入力からこの共通部分を抽出する場所:

  went out one day,[LF]
 over the hills and up away.[LF]
 Mother Duck said, "Quack Quack Quack Quack",[LF]

最後に、入力の最後の11文字を追加し" came back."ます。



1
@Shaggyよくできました。ありがとう!
アーナルド

2
execページがリロードされたときに提案する別のコメントを投稿するだけでした。素晴らしい心...!
シャギー

11

Pythonの3267の263 254バイト

@ovsのおかげで4バイト節約

def f(s):
 for a in zip(T[2:]+T,T):s=s.replace(*a)
 return s
T="8:9:and allHO1BnoneHT2No1T3Nt2F4Nt3FiveINf4MotherD herself"
for r in "H of theI,4ourI,3hreeI,2woI,1neL:,ILs:,L littleD,D duck,NBonly ,Bbut ".split(','):T=T.replace(r[0],r[1:])
T=T.split(':')

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

関連する部分を次の詩のそれぞれの部分で置き換えることにより機能します。

事前初期化後T['8', '9', 'and all of the little ducks', 'One little duck', 'but none of the little ducks', 'Two little ducks', 'but only one little duck', 'Three little ducks', 'but only two little ducks', 'Four little ducks', 'but only three little ducks', 'Five little ducks', 'but only four little ducks', 'Mother duck herself']です。

代替Python 2、252バイト

によって@ovs

lambda s:reduce(lambda s,a:s.replace(*a),zip(T[2:]+T,T),s)
T="8:9:and allHO1BnoneHT2No1T3Nt2F4Nt3FiveINf4MotherD herself"
for r in "H of theI,4ourI,3hreeI,2woI,1neL:,ILs:,L littleD,D duck,NBonly ,Bbut ".split(','):T=T.replace(r[0],r[1:])
T=T.split(':')

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


for a in zip(T,T[-2:]+T):s=s.replace(*a)264バイト。
ovs

またはlambda s:reduce(lambda s,a:s.replace(*a),zip(T,T[-2:]+T),s)、Python 2で262バイトの場合
ovs

おかげで@ovs、私はいくつかのことをreoderingし、使用して263にそれを得たT[2:]代わりにT[-2:]
ブラックフクロウカイ


7

Java 10、347バイト

s->{String L=" little duck",M="Mother duck herself";int i=9;for(var t:("ive;Four;hree;Two"+L+"s;One"+L+";four;two"+L+"s;only one"+L+";but none;and all of the;"+M).split(";"))s=s.replace(t,++i+"");for(var t:("Five"+L+"s;but only four;and all;none of the"+L+"s;one"+L+";three;"+M+";One"+L+";wo;Three;our").split(";"))s=s.replace(i--+"",t);return s;}

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

説明:

私たちは、最初の範囲内の整数で一つ一つにすべての部品を交換、その後、これらの整数はその代替にバックします。これが2つのステップで行われる理由は、そうでなければ置換を置き換えるからです。[10,21]

s->{                     // Method with String as both parameter and return-type
  String L=" little duck",M="Mother duck herself";
                         //  Two temp strings to save bytes
  int i=9;               //  Temp replacement integer, starting at 9
  for(var t:("ive;Four;hree;Two"+L+"s;One"+L+";four;two"+L+"s;only one"+L+";but none;and all of the;"+M).split(";"))
                         //  Loop over the parts to replace:
    s=s.replace(t,       //   Replace the part,
                ++i+""); //   with the integer pre-incremented by 1
  for(var t:("Five"+L+"s;but only four;and all;none of the"+L+"s;one"+L+";three;"+M+";One"+L+";wo;Three;our").split(";"))
                         //  Then loop over the parts to replace with in reverse:
    s=s.replace(i--+"",  //   Replace the (post-decrementing) integer,
    t);                  //   with the replacement-part
  return s;}             //  And then return the modified String as result

7

T-SQL、407の390 388 382バイト

DECLARE @ CHAR(999)=REPLACE(REPLACE('SELECT CASE LEFT(v,2)WHEN''Fi74,''Four''),122,4,''three'')WHEN''Fo74,''Three''),123,5,''two'')WHEN''Th75,''Two''),121,16,''on#'')WHEN''Tw716,''On#''),115,20,''none of th#s'')WHEN''On715,''Mother duck herself''),115,8,''and all'')WHEN''Mo719,''Fiv#s''),113,14,''but only four'')END FROM i',7,'''THEN STUFF(STUFF(v,1,'),'#','e little duck')EXEC(@)

入力は、IOルールに従って、フィールド持つ既存のテーブルを介して行われますiVVARCHAR(MAX)v

数回のバイト節約REPLACEの後、次を動的SQLとして実行します。

SELECT CASE LEFT(v,2)
       WHEN'Fi'THEN STUFF(STUFF(v,1,4,'Four'),122,4,'three')
       WHEN'Fo'THEN STUFF(STUFF(v,1,4,'Three'),123,5,'two')
       WHEN'Th'THEN STUFF(STUFF(v,1,5,'Two'),121,16,'one little duck')
       WHEN'Tw'THEN STUFF(STUFF(v,1,16,'One little duck'),115,20,'none of the little ducks')
       WHEN'On'THEN STUFF(STUFF(v,1,15,'Mother duck herself'),115,8,'and all')
       WHEN'Mo'THEN STUFF(STUFF(v,1,19,'Five little ducks'),113,14,'but only four')END
FROM i

CASEステートメントとSTUFFコマンドを使用して、リストされた位置に文字を挿入/上書きします。

編集

  1. 元の(下記)をまったく異なる戦略に置き換えます
  2. スペースのLEFT代わりに切り替えてSUBSTRINGスペースを削除することで2バイトを節約しました
  3. 変数をCHAR2番目に変更し、余分な文字を2番目に移動して6バイトを節約しましたREPLACE(ありがとう、@ CDC!)

別の方法(置換後、フォーマット済み)を使用した最初のバージョンを次に示します。

DECLARE @ VARCHAR(MAX)
SELECT @=v FROM i
SELECT @=REPLACE(@,PARSENAME(value,2),PARSENAME(value,1))
FROM string_split('e.but none.and all
                  -e.One little duck.Mother duck herself
                  -o.only one little duck.none of the little ducks
                  -o.Two little ducks.One little duck
                  -r.two little ducks.one little duck
                  -r.Three.Two
                  -u.three.two
                  -u.Four.Three
                  -v.four.three
                  -v.Five.Four
                  -t.and all of the.but only four
                  -t.Mother duck herself.Five little ducks','-')
WHERE LEFT(value,1)=SUBSTRING(@,3,1)
PRINT @

STRING_SPLITそしてPARSENAME、行と列を経由して、文字列の中へ侵入するために使用されている-.セパレータを。

最初の列は、入力詩の3文字目と一致するキー文字です(アイデア@ Night2に感謝します)。2番目と3番目は、その詩のために実行されている置換です。


最初の解決策として、「VARCHAR(MAX)」の代わりに「CHAR(700)」を使用すると、3バイト節約できます。また、別の3を得るためにあなたの「小さなアヒル」には、あなたの代わりに「E小さなアヒル」を行うことができ、各交換に#の前に電子を削除
CDC

ところで、本当に楽しいソリューション。私はformatmessageを使用して、非常に近くなりましたが、完全ではありません。
CDC

良い提案、@ CDC、ありがとう!
BradC

6

Python 2、1034バイト

これが私のコードです!シンプルな辞書を採用しています。このコードを実行した後、任意の詩を入力でき、次の詩を出力します。

PS:このチャンネルは初めてで、これが私の最初の投稿です。私はこのチャレンジが本当に好きだったので、試してみることにしました。私を修正してください。

import sys
i=sys.stdin.readlines()
s={"Mother":"""Five little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only four little ducks came back.""",
"Five":"""Four little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only three little ducks came back.""",
"Four":"""Three little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only two little ducks came back.""",
"Three":"""Two little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only one little duck came back.""",
"Two":"""One little duck went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but none of the little ducks came back.""",
"One":"""Mother duck herself went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
and all of the little ducks came back."""}
print s[i[0].split(" ")[0]]

11
サイトへようこそ!通常、辞書はソースの一部として数えます。課題の一部は、これを可能な限り小さくすることです。これを短縮する方法もいくつかあります。1)読みやすくするためのポイントが得られないので、1文字の変数名(xまたはa)を使用できます。2)Pythonは空白文字にかなり寛容なので、空白文字の一部も削除してみます。たとえば、周りにスペースは必要ありません=。最後に、Pythonでゴルフをするためのページがあり、ゲームにアクセスできます。
小麦ウィザード

おめでとうございます!それは役に立ちます。ありがとうございます!:)
Prachiti Prakash Prabhu

1
あなたは、不要な空白や変数を削除するインポート避けることで簡単にゴルフこのことができますsys例えばを使用してraw_input()あなたが最も確かに歌の繰り返しセクションを取り出し、別々にそれらを追加する必要がありますなど、辞書のキーを短縮
ジョー・キング

@JoKingは、これが私の最初の投稿であり、あまり考えていませんでした。試してみたかっただけなのですが、今は思いつきました。私の次の投稿は、これよりもはるかに良くて短くなります-すべての皆さんに感謝します..私を助けてください!:)
Prachiti Prakash Prabhu

6

PHP(7.4)、253 247バイト

「配列内のアンパック」の助けを借りて、置換配列の構築方法を改善することにより、-6バイト。

<?=strtr($argv[1],array_combine([0,1,...$a=[Five.$l=($o=" little duck").s,($b="but only ").four.$l,Four.$l,$b.three.$l,Three.$l,$b.two.$l,Two.$l,$b.one.$o,One.$o,"but none of the$l","Mother duck herself","and all of the$l"]],[...$a,$a[0],$a[1]]));

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

これにより、すべての可能な置換(使用済み12 +未使用2)のkey=>valueフォーマットの配列が作成されます。例:['Mother duck herself' => 'Five little ducks', etc...]そして、strtrを使用してそれらを単に置き換えます。

唯一おもしろいのは、PHP 7.4の新機能である「配列内のアンパック」を初めて使用したことです。


PHP、264バイト

<?=str_replace(($a=[[Five.$l=($o=" little duck").s,($b="but only ").four.$l],[Four.$l,$b.three.$l],[Three.$l,$b.two.$l],[Two.$l,$b.one.$o],[One.$o,"but none of the$l"],["Mother duck herself","and all of the$l"]])[$i=strpos(vuroet,($v=$argv[1])[2])],$a[++$i%6],$v);

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

各詩の異なる単語を配列に保存しました。入力が一意であるため、入力が3番目の文字を使用している詩を見つけます(vuroet)。それから、私はその詩の異なる単語を次の詩の異なる単語に置き換えるだけです。


5

クリーン、352バイト

import StdEnv,Text
$n={#"Five"+e+"four"+d,"Four"+e+"three"+d,"Three"+e+"two"+d,"Two"+e+"one"+a,"One"+a+b+"but none"+f,"Mother duck herself"+b+"and all"+f}.[indexOf{n.[2]}"tvuroe"]+" came back."
a=" little duck"
b=" went out one day,\nover the hills and up away.\nMother Duck said, \"Quack Quack Quack Quack\",\n"
d=a+"s"
e=d+b+"but only "
f=" of the"+d

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



3

PowerShell356 343 340 336バイト

param($p)$l,$M=' little duck','Mother duck herself'
("ive!our;four!three;hree!wo;Four!Three;two!one;s c! c;Two!One;s w! w;only one!none of the;k c!ks c;One$l!$M;but none!and all;$M!Five$l`s;and all of the!but only four"-split';')[$(switch -r($p){^Fi{0,1}^Fo{2,3}^Th{2,4,5}^Tw{6..9}^O{10,11}^M{12,13}})]|%{$p=$p-creplace($_-split'!')}
$p

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

より読みやすいバージョン:

param($p)
$l, $M = ' little duck', 'Mother duck herself'
$replacements = @"
ive!our
four!three
hree!wo
Four!Three
two!one
s c! c
Two!One
s w! w
only one!none of the
k c!ks c
One$l!$M
but none!and all
$M!Five$l`s
and all of the!but only four
"@ -split '\n'
$i = switch -regex ($p) { ^Fi { 0, 1 }
                          ^Fo { 2, 3 }
                          ^Th { 2, 4, 5 }
                          ^Tw { 6..9 }
                          ^O  { 10, 11 }
                          ^M  { 12, 13 } }
$replacements[$i] | % { $p = $p -creplace ( $_ -split '!' ) }
$p

3

PowerShellの265の 263 255 251 246バイト

$d='Five1four2s,Four1three2s,Three1two2s,Two1one2,One23but none52s,Mother duck herself3and all52s'-split','
'2s34',' little duck',-join($args-split'(\s)')[5..39],'but only ',' of the'|%{$d=$d-replace++$i,$_}
$d[+"$args"[2]*37%724%7]+' came back.'

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

総当たりを使って表現を見つけました+"$args"[2]*37%724%7

 verse | 3rd char. | ASCII code | *37%724%7
-------+-----------+------------+-----------
   0   |    'v'    |     118    |   1
   1   |    'u'    |     117    |   2
   2   |    'r'    |     114    |   3
   3   |    'o'    |     111    |   4
   4   |    'e'    |     101    |   5
   5   |    't'    |     116    |   0

@Arnauldに感謝し3rd charます。


2

Japt v2.0a0、143 バイト

単一の詩を置換してエンコードしようとしましたが、最終的には、アーナルドのソリューションを適応させることは短くなりました。うまくいけば、もっと短くなるかもしれないが、いつ試してみるかわからないかもしれない別のアイデアを持っています。

tBn)i`Fr4È(e3
Two4e0
MÇ@r Ýõ Êelf1d a¥23
O01¿t Í
23
TËG4two3
Five4fr3`·g`v`b¢Î)r\dÈ°g[V=` Ò¤ Ýõ`W=Uf/ w.*\n/s `  e`V±'sV+W+`¿t § `]

それを試してください -すべての詩が含まれています


2

Bash373 355バイト

ここであまりクレイジーなことはありません。簡単な数バイトの削減は、2文字の変数(a1、a2、a3、e1..e6)を1文字の変数に置き換えることです。

read a{1..3} b
read c
read d
read e{1..6}
W="$e1 $e2"
X="${e3^} $a2 $a3"
Y="$e5 $e6"
Z="$e4 $Y"
p=$X
case $a1 in M*)p="Five ${Y::12}";s="but only four $Y";;O*)p="${d::11} herself";s="and all of $Z";;Tw*)p=${X/s};s="$e1 none of the $a2 ducks $e6";;Th*)s="$W one $e4 duck $e6";;Fo*)s="$W two $Z";;Fi*)s="$W three $Z";;esac
echo $p $b;echo $c;echo $d;echo $s

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

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


2

05AB1E、134バイト

“€µ‚•„í†ìˆÈ“#’ „ê Ðœs’δJ樅î¥Ðœº¶s‚ìðδJD…€³€É δ쨦“€ƒ€Ÿ€‚€€““€³Šª€‚€€“‚’ „ê Ðœs ’δJ셋邃.δJU.•4Ôāl•|н2èk©è.ª?I„ 
ý#3.$17£ðý„ 
¶:,X®è?

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

私は05AB1Eが比較的新しいので、これはたくさんのゴルフをすることができます。

                ### Preparation of the output strings ###
“€µ‚•„í†ìˆÈ“        push "one two three four five"
#                   split that by spaces
’ „ê Ðœs’           push " little ducks"
δJ                  join each number with " little ducks"
ć¨                  separate "one little ducks" and drop the "s"
…î¥Ðœº¶             push "mother duck herself"
s                   swap it with "one little duck"
‚ì                  prepend both strings to the list ["mother duck herself", "one little duck", "two little ducks" ... ]
ðδJ                 append a space to each list entry
D                   duplicate it
…€³€É               push "but only "
δì                  prepend "but only " to each list entry
¨¦                  drop the first and last list entry
“€ƒ€Ÿ€‚€€“          push "and all of the"
“€³Šª€‚€€“          push "but none of the"
‚                   push the two strings into a list
’ „ê Ðœs ’δJ        append " little ducks " to each
ì                   prepend it to the sentence list ["and all of the little ducks ", "but none of the little ducks ", "but only one little duck " ...]
…‹é‚ƒ.              push "came back."
δJ                  append that to each list entry
U                   save that list in X for later use

                ### Determine which verse has to be answered ###
.•4Ôāl•             push "eoruvt"
|н2è                get the third letter of the input
k                   get the index of that letter in "eoruvt". Now we know which verse we must return
©                   save that index in ® for later use

                ### Print the answer strings ###
è.ª?                print that index of the first sentence list (first three words of answer)
I„                  join the four input strings by <space><newline>
ý
#                   split that by spaces
3.$                 cut off the first three words
17£                 keep only the next 17 words
ðý                  join remaining words by spaces
„ 
¶:                  replace <space><newline> by only <newline>
,                   print that ("went out ... Quack\",") 
X®è?                print the last line of answer

1

Perl 6、247バイト

{S:i/ne\sl.*?<(s//}o{m/..(.)(\S*)**3%\s(.**92).*(.**11)/;[(my$l=" little ducks")~$3 XR~"Mother duck herself$2and all of the","One{$l~=$2}but none of the","Five{$l~="but only "}four","Four{$l}three","Three{$l}two","Two{$l}one"]["eotvur".index($0)]}

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

特にフォームのリストの最後の5つの要素"num $l num-1"、または古い入力の適切な部分に一致する開始正規表現。


1

、156バイト

≔⌕tvuroe§θ²δ§⪪”↶0∨↘»≔xj➙⌈´βXPNLA‽⟦O⧴&▷V'¦³≧ψZρ⊞t”¶δF‹δ⁵”↶↧V4ⅉH‴G%”F‹δ⁴s⮌…⮌θ¹⁸⸿η⸿ζ⸿§⪪”}∧h⁴NQ≕Q^⪫ΦG✂q'ⅉMG./_⸿s⁵6P⁴″⊟±NNpOfBz↷Fι‖TM→⁻γ?k⁴ς!d⁵º'E,θ}x§-υ”¶δ✂ε±¹¹

オンラインでお試しください!リンクは、コードの詳細バージョンです。説明:

≔⌕tvuroe§θ²δ

最初の行の3番目の文字を見て、どの詩が欲しいかを考えます。

§⪪”↶0∨↘»≔xj➙⌈´βXPNLA‽⟦O⧴&▷V'¦³≧ψZρ⊞t”¶δF‹δ⁵”↶↧V4ⅉH‴G%”F‹δ⁴s⮌…⮌θ¹⁸

出力文字列のリストにインデックスを付けることにより、最初の行の最初の部分FiveFourThreeTwoOneMother duck herself。次に、必要に応じて印刷little ducks、入力行の最後の18文字(各節で常に同じです)を続けます。

⸿η⸿ζ⸿

中央の2行は、各節で常に同じです。

§⪪”}∧h⁴NQ≕Q^⪫ΦG✂q'ⅉMG./_⸿s⁵6P⁴″⊟±NNpOfBz↷Fι‖TM→⁻γ?k⁴ς!d⁵º'E,θ}x§-υ”¶δ✂ε±¹¹

最後の行ではlittle ducks、何らかの理由で選択肢のリストに含める方がゴルファーになりますが、最後の11文字は入力からコピーされます。


1

インク、353バイト

=d(v)
~temp n=(v?"Fi")+(v?"F")*4+(v?"Th")+(v?"T")*2+(v?"O")
{n-1:{n:{n-5:{n-4:{n-3:One|Two}|Three}|Four}|Five} little duck{n-2:s}|Mother duck herself} went out one day,
over the hills and up away,
Mother Duck said "Quack Quack Quack Quack",
{n-1:but {n-2:only {n:{n-5:{n-4:one|two}|three}|four}|none of the}|and all of the} little duck{n-3:s} came back.

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

まず、我々はにいる詩かを把握するのチェックをサブストリングの使用-開始時に数字の総額に簡単に十分なおかげだと- FTおよびO任意の他の場所で発生していない、とあなたはから第二、第四詩を区別することができますまたFiThそれぞれをチェックすることにより、1番目と3番目。

次に、インクが最適な処理を行い、条件付きで斑点のあるプレーンテキストを印刷します。最初はswitchステートメントを使用してみましたが、見た目は良くなりましたが、実際には長くなりました。sは変数を使用するのに適した場所
だと思いますがQuack、文字列が大量に繰り返される場合、変数には十分なオーバーヘッドがあり、私がしようとしたすべての方法でコードが長くなります。たぶん、それは私がインクでゴルフをすることになっていないサインです。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.