# Duck, duck, gone!

Here is the (quite scary) Five little ducks song(it is not long):

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.


Your task is not to output this song. You should take a verse and output the next verse, cyclically (the next verse of the last verse is the first verse).

## Rules

• Input/output will be taken via our standard input/output methods.
• The exact verse must be outputted, and there should be no differences when compared to the song lyrics. The input will not be different when it is compared to the song lyrics too.

## Examples

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.


Expected:

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.


Expected:

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.


## The Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

## Language Name, N bytes


where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes


If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes


You can also make the language name a link which will then show up in the snippet:

## [><>](https://esolangs.org/wiki/Fish), 121 bytes


/* Configuration */

var QUESTION_ID = 193467; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 8478; // This should be the user ID of the challenge author.

/* App */

return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(a) {
});
comment_page = 1;
}
});
}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(c) {
if (c.owner.user_id === OVERRIDE_USER)
});
else process();
}
});
}

var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

function getAuthorName(a) {
return a.owner.display_name;
}

function process() {
var valid = [];

var body = a.body;
if(OVERRIDE_REG.test(c.body))
body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
});

var match = body.match(SCORE_REG);
if (match)
valid.push({
user: getAuthorName(a),
size: +match[2],
language: match[1],
});
else console.log(body);
});

valid.sort(function (a, b) {
var aB = a.size,
bB = b.size;
return aB - bB
});

var languages = {};
var place = 1;
var lastSize = null;
var lastPlace = 1;
valid.forEach(function (a) {
if (a.size != lastSize)
lastPlace = place;
lastSize = a.size;
++place;

.replace("{{NAME}}", a.user)
.replace("{{LANGUAGE}}", a.language)
.replace("{{SIZE}}", a.size)

var lang = a.language;
lang = jQuery('<a>'+lang+'</a>').text();

languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link};
});

var langs = [];
for (var lang in languages)
if (languages.hasOwnProperty(lang))
langs.push(languages[lang]);

langs.sort(function (a, b) {
if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) return -1;
return 0;
});

for (var i = 0; i < langs.length; ++i)
{
var language = jQuery("#language-template").html();
var lang = langs[i];
language = language.replace("{{LANGUAGE}}", lang.lang)
.replace("{{NAME}}", lang.user)
.replace("{{SIZE}}", lang.size)
language = jQuery(language);
jQuery("#languages").append(language);
}

}
body {
text-align: left !important;
display: block !important;
}

width: 290px;
float: left;
}

#language-list {
width: 500px;
float: left;
}

font-weight: bold;
}

table td {
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="language-list">
<h2>Shortest Solution by Language</h2>
<table class="language-list">
<tr><td>Language</td><td>User</td><td>Score</td></tr>
<tbody id="languages">

</tbody>
</table>
</div>
<tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>

</tbody>
</table>
</div>
<table style="display: none">
</tbody>
</table>
<table style="display: none">
<tbody id="language-template">
</tbody>
</table>

• I remember the words to this being slightly different when I was young, many moons ago. But I also remember being traumatised by it! Where were those missing ducklings for all those days?! Why was nobody out looking for them?! And what sort of irresponsible mother manages to lose so many children and keeps letting the rest of them out to play?! The horror! – Shaggy Sep 24 '19 at 9:58
• Possible duplicate. Just kidding :) – Night2 Sep 24 '19 at 12:28
• That song lyrics sure made me go through a roller coaster of emotions. – Num Lock Sep 25 '19 at 10:04
• I listened to the YouTube video I posted here yesterday, twice, just twice. Now that song is embedded into my brain, anywhere I go, anything I do, I keep hearing it! Help... – Night2 Sep 25 '19 at 12:24
• Any reason the capitalization on "Mother duck" and "Mother Duck" is different in the 2 places it is used in the last verse? – Chill Sep 26 '19 at 18:00

# Stax, 115 111 bytes

τ*^&k─Zè0µ9┬█◘çl╟☼:Drσ59ò╠▄┴╢Q♂╔¡ô╜Oa╣▀yèA÷╨%^♀█Ö+╡◄ì=∙%╧o▌Θ<▲Çα¿╗√;1°┼╤V◘ú┐♥▒ÇM☼b╩░o]YaL4░ƒ%(Æ♫Q0æÆä⌂¡╘○Eâó╪¡  Run and debug it All the verses as test cases • When you run it with "One little duck", it responds "little ducknd little duckll of the little ducks came back." in the last line. – Dorian Oct 2 '19 at 10:25 • The bug has been fixed at no cost in size. It was actually about a 2-byte cost, and and offsetting 2-byte savings elsewhere, although bytes are kind of hard to measure here, since the changes aren't exactly byte aligned inside compressed string literals, or even in the final program. – recursive Oct 2 '19 at 16:26 # JavaScript (ES9), 227 bytes This is similar to the Node version below but uses a formula based on parseInt() instead of Buffer() to identify the input verse. This is ES2018 (aka ES9) because we're using a regular expression with the /s flag (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)  Try it online! ### How? In this version, we parse the entire input verse as base 30 (0 to t) and perform a bitwise AND with 7. The parsing stops on the first invalid character, leading to:  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 bytes Saved 2 bytes thanks to @Shaggy 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)  Try it online! ### How? The third character of each input verse can be used as a unique identifier. By taking its ASCII code modulo 9, we get:  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  The output verses are encoded with the following templates:  verse | template -------+--------------------------------- 0 | 'Five4four3' 1 | 'Four4three3' 2 | 'Three4two3' 3 | 'Two4one0' 4 | 'One01but none23' 5 | 'Mother duck herself1and all23'  Where each digit is replaced with a string according to the following table:  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 '  Where the regular expression / w.*\n/s extracts this common part from the input:  went out one day,[LF] over the hills and up away.[LF] Mother Duck said, "Quack Quack Quack Quack",[LF]  We finally add the last 11 characters of the input, which is " came back.". • 231 – Shaggy Sep 24 '19 at 12:00 • @Shaggy Nicely done. Thanks! – Arnauld Sep 24 '19 at 12:08 • Was just posting another comment to suggest exec when the page reloaded. Great minds ... ! – Shaggy Sep 24 '19 at 12:14 # Python 3, 267 263 254 bytes 4 bytes saved thanks to @ovs 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(':')  Try it online! Works by replacing the relevant parts by the respective parts of the next verse. After the preinitialisation, T is ['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']. # Alternative Python 2, 252 bytes by @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(':')  Try it online! • for a in zip(T,T[-2:]+T):s=s.replace(*a) for 264 bytes. – ovs Sep 24 '19 at 11:17 • Or lambda s:reduce(lambda s,a:s.replace(*a),zip(T,T[-2:]+T),s) for 262 bytes in Python 2. – ovs Sep 24 '19 at 11:19 • @ovs Thanks, I got it to 263 with reodering some things and using T[2:] instead of T[-2:] – Kateba Sep 24 '19 at 13:18 # QuadR, 257 242 bytes -14 thanks to Black Owl Kai, -1 thanks to Kevin Cruijssen ive Four hree Two( little duck)s One little( duck) Mother( duck) herself four two( little duck)s only on(e little duck) but none and all of the our Three wo One\1 Mother\1 herself Five little\1s three one\1 none of th\1s and all but only four  Try it online! # T-SQL, 407 390 388 382 bytes 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(@)  Input is via a pre-existing table $$\i\$$ with VARCHAR(MAX) field $$\v\$$, per our IO rules. After a couple of byte-saving REPLACEs, executes the following as dynamic 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  Uses a CASE statement and STUFF commands to insert/overwrite characters at the listed positions. EDITS: 1. Replace original (below) with an entirely different strategy 2. Saved two bytes by switching to LEFT instead of SUBSTRING and eliminating a space 3. Saved 6 bytes by changing variable to CHAR and moving an extra letter into the second REPLACE (thanks, @CDC!) Here's my first version, using a different method (post-replacement, formatted): 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 and PARSENAME are used to break a string into rows and columns via - and . separators. The first column is a key character that is matched against the 3rd letter of the input verse (thanks for the idea, @Night2). The second and third are the replacements being performed for that verse. • First solution, if you use "CHAR(700)" instead of "VARCHAR(MAX)" you can save 3 bytes. Also in your " little duck", you can instead do "e little duck" and remove the e before # on each replacement to get another 3. – CDC Sep 27 '19 at 19:26 • BTW, really fun solution. I used formatmessage to get very close to you, but not quite. – CDC Sep 27 '19 at 19:28 • Good suggestions, @CDC, thanks! – BradC Sep 27 '19 at 19:49 # Java 10, 347 bytes 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;}  Try it online. Explanation: We first replace all parts one by one with integers in the range $$\[10,21]\$$, and then these integers back to their replacements. The reason this is done in two steps, is because we would otherwise replace replacements. 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  # Python 2, 1034 bytes This is my code! It employs a simple dictionary. After running this code, you can enter any verse and it will output the next verse. PS: I am new to this channel and this is my first post. I really liked this challenge so decided to give it a try. Please feel free to correct me. 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]]  • Welcome to the site! Usually we would count the dictionary as part of the source. Part of the challenge would be to try and make this as small as possible. There are also a few ways you could shorten this. 1) Since you don't get any points for being readable you can use single character variable names (e.g. x or a) 2) Python is pretty permissive with whitespace so I would try removing some of your whitespace also. For example you don't need spaces around =. Lastly We have a page for golfing in python you can visit to up your game. – Wheat Wizard Sep 24 '19 at 22:22 • wow @SriotchilismO'Zaic! that's helpful..thank you! :) – Prachiti Prakash Prabhu Sep 24 '19 at 22:44 • You can easily golf this by removing unnecessary whitespace and variables, avoiding importing sys by using e.g. raw_input(), shortening the key of the dictionary, etc. You should most definitely take out the repeated sections of the song and add them seperately – Jo King Sep 26 '19 at 5:38 • @JoKing as I mentioned this is my very first post and I didn't put much thought into this. Just wanted to give it a try, but I now get the idea. My next post is going to be much much better and shorter than this--all thanks to you guys..helping me out! :) – Prachiti Prakash Prabhu Sep 26 '19 at 17:34 # PHP (7.4), 253 247 bytes -6 bytes by improving how the replacements array is built with more help from "Unpacking inside arrays". <?=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]]));


Try it online!

This creates an array of every possible replacement (12 used + 2 unused) in a key=>value format. Example: ['Mother duck herself' => 'Five little ducks', etc...] and then just replaces those using strtr.

The only interesting thing is my first ever usage of "Unpacking inside arrays" which is a new feature in PHP 7.4.

<?=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);  Try it online! I have stored different words of each verse in an array. I find which verse the input is using third character of the input as it is unique (vuroet). Then I simply replace different words of that verse with different words of the next verse. # Clean, 352 bytes 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


Try it online!

x=>$@"{l[g=x[2]*37%724%7]}{g-5:; little} duck{g-4: herself;s;\} went out one day, {(x=x.Split('\n'))[1]} {x[2]} {g-5:and;but} {g-4:all;only;none} {(g>3?"of the":l[g+1].ToLower())} little duc{g%3:ks;;k} came back.";var l=" Four Three Two One Mother".Split();int g  Try it online! # PowerShell, 356343340 336 bytes 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$ls;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$ls
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


# PowerShell, 265263255251 246 bytes

$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.'


Try it online!

I used the brute force to find the expression +"$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  Thanks @Arnauld for the 3rd char. # 05AB1E, 134 bytes “€µ‚•„í†ìˆÈ“#’ „ê Ðœs’δJć¨…î¥Ðœº¶s‚ìðδJD…€³€É δì¨¦“€ƒ€Ÿ€‚€€““€³Šª€‚€€“‚’ „ê Ðœs ’δJì…‹é‚ƒ.δJU.•4Ôāl•|н2èk©è.ª?I„ ý#3.$17£ðý„
¶:,X®è?


Try it online!

Since i'm relatively new to 05AB1E, this can maybe be golfed a lot

                ### 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  # Japt v2.0a0, 143 bytes Tried encoding a single verse with replacements but, in the end, adapting Arnauld's solution ended up being shorter. Have another idea that might, hopefully, work out shorter again but don't know when I'll get to try it. tBn)iFr4È(e3 Two4e0 MÇ@r Ýõ Êelf1d a¥23 O01¿t Í 23 TËG4two3 Five4fr3·gvb¢Î)r\dÈ°g[V= Ò¤ ÝõW=Uf/ w.*\n/s  eV±'sV+W+¿t § ]  Try it - includes all verses # Charcoal, 156 bytes ≔⌕tvuroe§θ²δ§⪪”↶0∨↘»≔xj➙⌈´βＸPＮLA‽⟦O⧴＆▷V'¦³≧ψZρ⊞t”¶δＦ‹δ⁵”↶↧V4ⅉＨ‴G%”Ｆ‹δ⁴s⮌…⮌θ¹⁸⸿η⸿ζ⸿§⪪”}∧h⁴ＮＱ≕Q^⪫ΦＧ✂q'ⅉＭG./_⸿s⁵6P⁴″⊟±ＮNpOfBz↷Ｆι‖ＴM→⁻γ？k⁴ς!d⁵º'E,θ}x§-υ”¶δ✂ε±¹¹  Try it online! Link is to verbose version of code. Explanation: ≔⌕tvuroe§θ²δ  Look at the third character of the first line to work out which verse we want. §⪪”↶0∨↘»≔xj➙⌈´βＸPＮLA‽⟦O⧴＆▷V'¦³≧ψZρ⊞t”¶δＦ‹δ⁵”↶↧V4ⅉＨ‴G%”Ｆ‹δ⁴s⮌…⮌θ¹⁸  Output the first part of the first line by indexing into the list of strings Five, Four, Three, Two, One, Mother duck herself. Then print little duck and s as appropriate, followed by the last 18 characters of the input line (which are always the same on each verse). ⸿η⸿ζ⸿  The middle two lines are always the same on each verse. §⪪”}∧h⁴ＮＱ≕Q^⪫ΦＧ✂q'ⅉＭG./_⸿s⁵6P⁴″⊟±ＮNpOfBz↷Ｆι‖ＴM→⁻γ？k⁴ς!d⁵º'E,θ}x§-υ”¶δ✂ε±¹¹  For the last line it turns out to be golfier to include little ducks in the list of alternatives for some reason, but the last 11 characters are still copied from the input. # Bash, 373 355 bytes Nothing too crazy here. An easy few byte reduction would be to replace the two-character variables (a1,a2,a3,e1..e6) with single character ones. 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


Try it online!

Try it online!

# Perl 6, 247 bytes

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


Try it online!

Definitely golfable, especially the last 5 elements in the list in the form "num $l num-1", or the starting regex that matches the right parts of the old input. # ink, 353 bytes =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.  Try it online! First, uses substring checks to figure out what verse we're in - that's easy enough thanks to the capitalisation of the numbers at the start - F, T and O don't occur in any other places, and you can distinguish the second and fourth verse from the first and third by also checking for Fi and Th respectively. Then we just do what ink does best and print plain text specked with conditionals. I tried using switch statements at first, but while that looked nicer, it actually ended up longer. You'd think the Quacks would be a good place to use variables, what with a string being repeated a bunch, but variables come with enough overhead that every way I tried to do that made the code longer. Maybe that's a sign I'm not supposed to golf in ink. # Deadfish~, 7572 bytes {{i}ddd}c{i}{i}{i}iiiiic{i}iiic{d}{d}iiic{{d}iii}ic{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{i}ddc{{d}ii}dddc{{i}d}dddc{d}{d}iic{i}dciiiiiic{{d}ii}ddddc{{i}dd}dciiiiiicdc{{d}ii}ddddc{{i}dd}dcdc{d}ic{{d}iii}ic{{i}ddd}ddcdddc{i}{i}iiiic{{d}ii}iiic{d}{d}{d}ddddc{{i}}ic{i}dddc{d}{d}iiic{i}iiic{{d}ii}ddc{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiciciiicc{i}dddc{{d}ii}dddc{{i}dddd}iiiiic{i}iiic{d}c{{d}iii}iic{{i}dd}iiiiicdddddc{{d}ii}c{{i}dddd}iiiiic{i}{i}iic{d}{d}ddc{i}{i}iiiic{{d}iii}dddddc{d}{d}{d}ddddddc{{i}ddd}dddc{i}{i}{i}iiiiciiiiic{d}ddcdddc{i}iiic{{d}ii}ddc{i}{i}{i}iiiiiic{{i}ddddd}dc{d}{d}iic{i}ddc{{d}iii}dddddc{{i}dd}iiic{d}{d}iic{i}ddcdddddc{{d}iiiii}ddddddc{d}ddciic{{i}ddddd}dddc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddc{i}c{d}{d}{d}ddddc{{i}d}ddc{i}{i}dcdc{{d}ii}ddddc{{i}dd}dcdcddc{i}iiic{{d}i}ic{{i}ddd}c{i}dciiiiiicdddc{{d}ii}ddc{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{i}ddc{{d}ii}dddc{{i}ddd}dddcddc{i}iic{d}iic{{d}iii}ic{{i}dddd}iiiiiicdciic{i}ddc{{d}iiii}dc{d}{d}{d}ddddddcc{{i}dddd}c{{i}dddddd}iciiiiiicdddc{{d}ii}ddc{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{i}ddc{{d}ii}dddc{{i}d}dddc{d}{d}iic{i}dciiiiiic{{d}ii}ddddc{{i}dd}dciiiiiicdc{{d}ii}ddddc{{i}dd}dcdc{d}ic{{d}iii}ic{{i}ddd}ddcdddc{i}{i}iiiic{{d}ii}iiic{d}{d}{d}ddddc{{i}}ic{i}dddc{d}{d}iiic{i}iiic{{d}ii}ddc{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiciciiicc{i}dddc{{d}ii}dddc{{i}dddd}iiiiic{i}iiic{d}c{{d}iii}iic{{i}dd}iiiiicdddddc{{d}ii}c{{i}dddd}iiiiic{i}{i}iic{d}{d}ddc{i}{i}iiiic{{d}iii}dddddc{d}{d}{d}ddddddc{{i}ddd}dddc{i}{i}{i}iiiiciiiiic{d}ddcdddc{i}iiic{{d}ii}ddc{i}{i}{i}iiiiiic{{i}ddddd}dc{d}{d}iic{i}ddc{{d}iii}dddddc{{i}dd}iiic{d}{d}iic{i}ddcdddddc{{d}iiiii}ddddddc{d}ddciic{{i}ddddd}dddc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddc{i}c{d}{d}{d}ddddc{{i}d}ddc{i}{i}dcdc{{d}ii}ddddc{{i}dd}dcdcddc{i}iiic{{d}i}ic{{i}dd}iiiic{d}ddc{i}c{d}dddcc{{d}iii}ic{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{i}ddc{{d}ii}dddc{{i}ddd}dddcddc{i}iic{d}iic{{d}iii}ic{{i}dddd}iiiiiicdciic{i}ddc{{d}iiii}dc{d}{d}{d}ddddddcc{{i}ddd}iiiic{i}{i}c{i}c{d}dddcc{{d}iii}ic{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{i}ddc{{d}ii}dddc{{i}d}dddc{d}{d}iic{i}dciiiiiic{{d}ii}ddddc{{i}dd}dciiiiiicdc{{d}ii}ddddc{{i}dd}dcdc{d}ic{{d}iii}ic{{i}ddd}ddcdddc{i}{i}iiiic{{d}ii}iiic{d}{d}{d}ddddc{{i}}ic{i}dddc{d}{d}iiic{i}iiic{{d}ii}ddc{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiciciiicc{i}dddc{{d}ii}dddc{{i}dddd}iiiiic{i}iiic{d}c{{d}iii}iic{{i}dd}iiiiicdddddc{{d}ii}c{{i}dddd}iiiiic{i}{i}iic{d}{d}ddc{i}{i}iiiic{{d}iii}dddddc{d}{d}{d}ddddddc{{i}ddd}dddc{i}{i}{i}iiiiciiiiic{d}ddcdddc{i}iiic{{d}ii}ddc{i}{i}{i}iiiiiic{{i}ddddd}dc{d}{d}iic{i}ddc{{d}iii}dddddc{{i}dd}iiic{d}{d}iic{i}ddcdddddc{{d}iiiii}ddddddc{d}ddciic{{i}ddddd}dddc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddc{i}c{d}{d}{d}ddddc{{i}d}ddc{i}{i}dcdc{{d}ii}ddddc{{i}dd}dcdcddc{i}iiic{{d}i}ic{{i}dd}iiiiciiic{d}iic{{d}ii}ic{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{i}ddc{{d}ii}dddc{{i}ddd}dddcddc{i}iic{d}iic{{d}iii}ic{{i}dddd}iiiiiicdciic{i}ddc{{d}iiii}dc{d}{d}{d}ddddddcc{{i}ddd}iiiic{i}{i}{i}iiiiic{d}iic{{d}ii}ic{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{i}ddc{{d}ii}dddc{{i}d}dddc{d}{d}iic{i}dciiiiiic{{d}ii}ddddc{{i}dd}dciiiiiicdc{{d}ii}ddddc{{i}dd}dcdc{d}ic{{d}iii}ic{{i}ddd}ddcdddc{i}{i}iiiic{{d}ii}iiic{d}{d}{d}ddddc{{i}}ic{i}dddc{d}{d}iiic{i}iiic{{d}ii}ddc{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiciciiicc{i}dddc{{d}ii}dddc{{i}dddd}iiiiic{i}iiic{d}c{{d}iii}iic{{i}dd}iiiiicdddddc{{d}ii}c{{i}dddd}iiiiic{i}{i}iic{d}{d}ddc{i}{i}iiiic{{d}iii}dddddc{d}{d}{d}ddddddc{{i}ddd}dddc{i}{i}{i}iiiiciiiiic{d}ddcdddc{i}iiic{{d}ii}ddc{i}{i}{i}iiiiiic{{i}ddddd}dc{d}{d}iic{i}ddc{{d}iii}dddddc{{i}dd}iiic{d}{d}iic{i}ddcdddddc{{d}iiiii}ddddddc{d}ddciic{{i}ddddd}dddc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddc{i}c{d}{d}{d}ddddc{{i}d}ddc{i}{i}dcdc{{d}ii}ddddc{{i}dd}dcdcddc{i}iiic{{d}i}ic{{i}dd}dcdc{d}ic{{d}iii}ic{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{{d}iii}dddddc{{i}ddd}dddcddc{i}iic{d}iic{{d}iii}ic{{i}dddd}iiiiiicdciic{i}ddc{{d}iiii}dc{d}{d}{d}ddddddcc{{i}ddd}dc{i}{i}{i}ic{d}ic{{d}iii}ic{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{{d}iii}dddddc{{i}d}dddc{d}{d}iic{i}dciiiiiic{{d}ii}ddddc{{i}dd}dciiiiiicdc{{d}ii}ddddc{{i}dd}dcdc{d}ic{{d}iii}ic{{i}ddd}ddcdddc{i}{i}iiiic{{d}ii}iiic{d}{d}{d}ddddc{{i}}ic{i}dddc{d}{d}iiic{i}iiic{{d}ii}ddc{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiciciiicc{i}dddc{{d}ii}dddc{{i}dddd}iiiiic{i}iiic{d}c{{d}iii}iic{{i}dd}iiiiicdddddc{{d}ii}c{{i}dddd}iiiiic{i}{i}iic{d}{d}ddc{i}{i}iiiic{{d}iii}dddddc{d}{d}{d}ddddddc{{i}ddd}dddc{i}{i}{i}iiiiciiiiic{d}ddcdddc{i}iiic{{d}ii}ddc{i}{i}{i}iiiiiic{{i}ddddd}dc{d}{d}iic{i}ddc{{d}iii}dddddc{{i}dd}iiic{d}{d}iic{i}ddcdddddc{{d}iiiii}ddddddc{d}ddciic{{i}ddddd}dddc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddc{i}c{d}{d}{d}ddddc{{i}d}ddc{i}{i}dcdc{{d}ii}ddddc{{i}dd}ddcicdc{d}ic{{d}iii}ic{{i}dd}dc{d}ic{{d}iii}c{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{i}ddc{{d}ii}dddc{{i}ddd}dddcddc{i}iic{d}iic{{d}iii}ic{{i}dddd}iiiiiicdciic{i}ddc{{d}iiii}dc{d}{d}{d}ddddddcc{{i}ddd}dddc{i}{i}{i}iiiiciiiiic{d}ddcdddc{i}iiic{{d}ii}ddc{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{{d}iii}dddddc{{i}ddd}iicdddc{i}iiicic{d}ddddc{i}dddcddddddc{{d}iii}c{{i}d}dddc{d}{d}iic{i}dciiiiiic{{d}ii}ddddc{{i}dd}dciiiiiicdc{{d}ii}ddddc{{i}dd}dcdc{d}ic{{d}iii}ic{{i}ddd}ddcdddc{i}{i}iiiic{{d}ii}iiic{d}{d}{d}ddddc{{i}}ic{i}dddc{d}{d}iiic{i}iiic{{d}ii}ddc{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiciciiicc{i}dddc{{d}ii}dddc{{i}dddd}iiiiic{i}iiic{d}c{{d}iii}iic{{i}dd}iiiiicdddddc{{d}ii}c{{i}dddd}iiiiic{i}{i}iic{d}{d}ddc{i}{i}iiiic{{d}iii}dddddc{d}{d}{d}ddddddc{{i}ddd}dddc{i}{i}{i}iiiiciiiiic{d}ddcdddc{i}iiic{{d}ii}ddc{i}{i}{i}iiiiiic{{i}ddddd}dc{d}{d}iic{i}ddc{{d}iii}dddddc{{i}dd}iiic{d}{d}iic{i}ddcdddddc{{d}iiiii}ddddddc{d}ddciic{{i}ddddd}dddc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddddc{{i}ddddd}dc{i}{i}{i}iiiiiic{d}{d}ciic{i}ddc{{d}iii}dddc{i}c{d}{d}{d}ddddc{{i}d}dddc{i}iiic{d}c{{d}iii}iic{{i}dddd}iiiiic{i}icc{{d}iii}ddddddc{{i}dd}dc{d}ic{{d}iii}c{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiiiiicdddc{i}icc{d}iic{d}iiic{{d}iii}ic{{i}ddd}ddc{i}{i}dddc{d}{d}iic{i}ddc{i}ddc{{d}ii}dddc{{i}ddd}dddcddc{i}iic{d}iic{{d}iii}ic{{i}dddd}iiiiiicdciic{i}ddc{{d}iiii}dc{d}{d}{d}ddddddc  I honestly expected this not to fit at all. # Zsh, 270 bytes read {a..d} read e read f set cat case$a in
M*)a=Five
b=$5 c=$6
set but only four ${@:5};;O*)a=Mother b=$c
c=herself
1=and
2=all;;*o)a=One
c=duck
set but none of the ${@:4} 6+=s;;T*)a=Two 3=one 5=duck;;*r)a=Three 3=two;;*)a=Four 3=three;;esac <<Q$a $b$c $d$e
$f$@


Try it online!

Explanation:

# {a..d} expands to a b c d
# so, read four words and assign them to a, b, c, and d
# (d also gets all the extra words beyond the 4th)

# read two lines and store them in e and f

# assign the words in the remainder of the input
# to the numbered variables 1...
set cat

# if the first word...
case $a in # starts with M (i.e. Mother) M*) a=Five b=$5  # "little"
c=$6 # "ducks" # set the numbered variables #${@:5} is the existing numbered vars from 5 onwards
set but only four ${@:5} ;; # One O*) a=Mother b=$c       # "duck"
c=herself
1=and
2=all
;;
# ends with o (Two)
*o)
a=One
c=duck
set but none of the ${@:4} # "duck" -> "ducks" 6+=s ;; # Three T*) a=Two 3=one 5=duck ;; # Four *r) a=Three 3=two ;; # anything else (Five) *) a=Four 3=three ;; esac # now print: <<Q$a $b$c $d$e
$f$@
$$$$
`