Quack the Angry Duck
Java, 303 286 bytes
Saved 17 bytes thanks to @VoteToClose!
Not actually meant to be the shortest, I just thought it would be fun to try in Java.
Creates a list of string variables representing common strings, then creates an array of all the outputs, then prints the right one.
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];}
Ungolfed:
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];
}
This is my first answer on this site, so please tell me if I have done something wrong.
CJam, 108 90 85 bytes
"quack"">:U":D"scT¦{$ì"{269b22bSf*D}:F~[ZYB].*s.+s5/"ÿ3nÜïS{JÐø¦yûn"F*33/z]ri=zN*
Note that some characters are unprintable. Try it online!
Background
The first two outputs are incompressible in CJam.
Compressing the last output is straightforward. After stripping all linefeeds, we can split the resulting string at occurrences of >:U
, and compute the length of each resulting string of spaces.
That results in the array
[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]
which we can store efficiently by converting it from base 22 to base 269, yielding the digits
[255 12 51 110 220 239 83 123 74 208 248 166 121 251 110 17]
Since each digit is less than 256, we can store it as a single byte.
Finally, compressing the third output becomes easier if we transpose lines and columns:
> >
>
: :
UUUU
U
U
U
UUUU
Counting once more the spaces between non-whitespace characters, we get the array
[1 1 3 8 1 6 0 0 0 5 4 4 0 0 0 0 0]
which becomes
[115 159 99 84 166 123 36 236 6]
when transcoded from base 22 to base 269.
How it works
"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.
05AB1E, 162 159 157 bytes
Code
Dammit, way too long, but it's at least something:
">: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
Try it online!
Explanation
The first part of the code exists of ">:U"V
, which sets Y
to that string. After that, we just check if the input is equal to 3. That is done at the I3Qi
part. If equal, we print the giant magpie:
N = 3
It first starts with ð16×
which just pushes 16 space characters. After that, there is a number 7166b
. This covers the ">:U "
part, with a little help from Retina :). I used this script to convert the string to a binary number. After that, we get to the 1ð:0Y:
part, which replaces every 1
with a space character and every 0
with Y
, which has been set to >:U
. After that, we D
uplicate this string, store it in X
using U
and J
oin the stack. We pop this using ,
, which prints the full string with a newline. All the others after that are all based on the same principe. The if statement ends at the second }
.
The full conversion can be found here.
N = 2
We now check if the input is equal to 2. This is done at the ¹2Qi
part. After that, if equal, we push the space character 4 times using ð4×
. After that, we push the " U U"
string and store it using ©
(idea blatantly stolen from Jelly :p). We again J
oin the stack and print this with a newline. After that, we push the "> :"
string, retrieve the " U U"
using ®
, J
oin the stack and D
uplicate this string and print these both on the same line.
Short quiz, what will this do: " > "?®,
?
After printing the above string, we get the duplicate of the second line of the face, and print this (since it's the same as the 2nd line).
The last part covered by this case is:
ð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
This one is easier to explain:
¹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