perl -M5.010 -Mbigint, 8 orientations, 8 18 tasks, 1644 2840 bytes
####################################################iA;"/sv)=-=f{.{ei#
if(eof()){say+("11 *25 *\n7 4*10 *5 *10 4*" .##cAc##f.e[^ag.(-po$./lf#
"\n5 4*12 7*12 4*\n3 6*12 7*12 6*\n2 9*9 9*".##'+b##(.x^(yk$$$orp*^s(#
"9 9*\n 47*\n49*\n49*\n49*\n 47*\n 5*7 21*".##@wM##eYi$$$k3x_d =).ee#
"7 5*\n4 4*7 3*4 5*4 3*7 4*\n7 **7 *6 3*6 *".##@@E##o;tvc1g)[>#2$.+{o#
"7 **\n")=~s/(\d+)(\D)/$2 x$1/gre}else{chomp(##4`c##f/}]*.px1=%._(?$f#
$_=<>);if(/\D/){/^google/&¨$_=length}else##":B##(.$"$(b ]00.>?(_(#
{$_=sprintf"00%b",$_;$_=/00100(.{5})*$/?1:0}}##VQl##){_;v(s2,;#$1{?=)#
say;#[447}E<vFX**gd's<kN6iiX#gS0qnsHgj'M%um$###>fr##)2=$*(z)$son;s{<)#
=pod#+RvC!y-9UwQ7ImGlBV03'UoBoqY:#OR`6z&C_;0###$I7##{6<v({t}xa+-$as>{#
[$1=~y,a-zA-Z,A-Za-z,r]ige}};say;#zG}B2|M}TI###X^4##$}>=$sde[yQ2nya;{#
"ur new baby! :D"}}else{s[a([^aA]*)a?] ##l"}###/)u##_(;"cpvl0$s;=$ycs#
$/,grep$_,@x}else{$_="Congratulations on yo".##"(O##=?$[)lfs]x9s$1$ha#
' $'x$_,' |'x$_,'-'x$x,'~'x$x,'-'x$x);$_=join##ZSo##j{v$)ize+[Ja_}&oy#
;if(/^-?\d+$/){if($_){$x=1+2*($_<0?1:$_);@x=(##)<V##os=v$ts{$0Jy;)}m+#
if(eof()){$_="Hello, World!"}else{$_=<>;chomp##WJ+##iaa]c/}@x]^!$()p+#
###############################################JvE##nye"*/-x[}@!p?(;$#
###############F+g@,ZHTSgmA|[\N"0`EV(>QJ'=b(9]+FJY##"$i;(,>=1#>$&!?i_#
###########.###lq{$LWnQj&g|l27@'o}Tr@VFDBI`K#np#7g##"&oi$b{(]6>p&)!f;#
#9Tj=~7D#Sxy{##.YTb}.:7dj+t|4-8Fo\GZJ?E=L7CWYq-RVu##,}ufvp$0){/}=/)(r#
#7$_j;&Q,A$b###<M+agLQ5{_6z^mL6V:VVo;Azb`4<5tAUx9###A)y()c2,wwd}$x//e#
#L[vlh(sa#ya(##hOy>[A&.[usZ_Xzkgn^{qdp|2B{T-g5&$u+##.(;#/g}1h;0#n};\d#
#,zQS#wBpraB.##(Qrc\!&X(_i[Cd1o:vuq76kWY/g0v>xso8|##.?$/)d|)id'[%e/Do#
#{x]V;Gzdos."##eXBcnsw2l?ImMzjJ;0NO045|JIrUh\sT@wh##Z!ca{t|;lCxd$l^/}#
###LuyK/nf;)k##G{3|#3B)J\n"rG__@*w0,6h6m6\MLggprbN##,)=[#f$@eiU\_s()}#
#";M!aBwa x3r##Oj@;),oZ-Yh6gBXx*B-Aq|!Xg;vx!@O7V^_###/###.2x#####e####
#t"]#sLTrr$xa##p79<GL"e"STDrRWLVRHuQY`_zmq;wDu`3cD####################
#ru}~;b'Ggy)h#########################################################
#io#=rgr,/a/S###rof zzuBzziF:zzuB:zziF:_$?3%_$?5%_$?51%_$yas{))(foe(fi
#BYyr!vay_s$ ###Xat(\'7O(>#;a:na?/$*)...(]81[1^|8^/~=><yas}tixe;001..1
# a!l+7m$;.y###iv&.:!Pd.MSjhr6,|E+>cjA(%?NuLB"}ss#8H?<Otd~Bw0zy>#dop=
#yosrrm#m/")b###$#;yas}")".]]7[c$[)" ","___",'" "'," : "(."( n\".]]5
#pt;ae{;oy!6a##[c$[)"$,"\\","$,">"(.")".]]6[c$[)" ","< >","[ ]"," :"
#p yePVaMbkxB##."$(."(".]]4[c$[)"$,"/","$,"<"(./$.]]5[c$[)"$,"$,"/","$
#ayaD!~m,ar""##(.")".]]3[c$[)"-","O","o","."(.]]1[c$[)"$,"_",".",","(.
#Has!u#dyBao(##]]2[c$[)"-","O","o","."(."(".]]4[c$[)"$,"$,"\\","$(./$.
#"d;oodnd/ho(##]]0[c$[)")_*_(","\\_/ ",".....","_===_"(."$./$.]]0[c$[)
#=hytYoadsSd=##"___ ","_ ","___ ",""(."$=_$;g/./~=><}1-_${pam=c@{esle
#_"a!!pra~ x##}5=x _$;g//$..|..^/s;2=x _$;/$.)81x"|___"(=_${))(foe(fi
#$.sss=GD=""$#########################################################
Before explaining how it works, let me tell how I created the monster
above. I started off with 8 programs, each doing 1 to 3 tasks. Which task they do depends on the input (all input is read as a single line from STDIN
) they get: void, an integer, or a string. 8 programs handle void input, 6 handle integer input, and 4 handle string input. If there would be more tasks which take integer and/or string input, we could have handled 24 inputs.
Now, we take the 8 programs, and combine them in the following way:
###################PP=PP#
PROGRAM 1 TOP ##RRpRR#
PROGRAM 1 BOTTOM ##OOoOO#
=pod ##GGdGG#
PROGRAM 2 BOTTOM ##RR RR#
PROGRAM 2 TOP ##AA AA#
###################MM MM#
# # # #
# M M # #44 33#
# O O # # #
# T T # #TB BT#
#PT TP# #OO OO#
#OO OO# #PT TP#
#TB BT# # T T #
# # # O O #
#77 88# # M M #
# # # #
#MM MM###################
#AA AA## POT 6 MARGORP
#RR RR## MOTTOB 6 MARGORP
#GGdGG## dop=
#OOoOO## MOTTOB 5 MARGORP
#RRpRR## POT 5 MARGORP
#PP=PP###################
Any 'gaps' (whether from short lines, or how the programs are laid out) are filled with random characters, protected by comment characters.
Any lines starting with =pod
prevent Perl to see the rest of the program; this way we get to have two programs per rotation; flipping the program in the x-axis exposes the other program.
A few things need to be taken care off: programs should finish with semi-colon or a right-paren which closes a block. That way, the final statement is finished, and only then, Perl will recognized the =pod
as the start of a POD
section. Second, if we have a construct of the form s[pattern][replacement]
, with a newline between the s[pattern]
and [replacement]
, we must add a space after s[pattern]
. Otherwise, we may end up with s[pattern]#
, and that #
Perl will not see as a comment, but as a delimiter for the replacement part. With a space before the #
, Perl will treat it as a comment.
Up to the tasks!
No rotations, no mirroring
if(eof()){say+("11 *25 *\n7 4*10 *5 *10 4*" .
"\n5 4*12 7*12 4*\n3 6*12 7*12 6*\n2 9*9 9*".
"9 9*\n 47*\n49*\n49*\n49*\n 47*\n 5*7 21*".
"7 5*\n4 4*7 3*4 5*4 3*7 4*\n7 **7 *6 3*6 *".
"7 **\n")=~s/(\d+)(\D)/$2 x$1/gre}else{chomp(
$_=<>);if(/\D/){/^google/&¨$_=length}else
{$_=sprintf"00%b",$_;$_=/00100(.{5})*$/?1:0}}
say;
No input
Without input, this does the "In Honor of Adam West" task. We're using a simple encoded string, where repeated characters are encoded as NNc
, which means NN
times the character c
. The string is decoded and printed.
Try it online!
Integer input (non negative)
Now we determine whether the given number is a Rude Number. We take the number, get the binary representation, prepend 00
, and look whether the result contains 00100
followed by N
s 0
s and 1
s, where N
is a multiple of 5.
Try it online!
String input
For other inputs, if the input equals google
, we die. Otherwise, we print the length of the input.
Try it online!
No rotation, mirrored.
If we mirror the program, we effectively end up with:
if(eof()){$_="Hello, World!"}else{$_=<>;chomp
;if(/^-?\d+$/){if($_){$x=1+2*($_<0?1:$_);@x=(
' $'x$_,' |'x$_,'-'x$x,'~'x$x,'-'x$x);$_=join
$/,grep$_,@x}else{$_="Congratulations on yo".
"ur new baby! :D"}}else{s[a([^aA]*)a?] #
[$1=~y,a-zA-Z,A-Za-z,r]ige}};say;
No input.
The program prints out Hello, World!
. Nothing creative going on here.
Try it online!
Integer input
We do the "It's my Birthday :D" task. If the input equals 0
, we print out Congratulations on your new baby! :D
. For the input (N
) is positive, we start printing out N
candles, then a cake of width 2 * N - 1
. If the input is negative, we print a candleless cake, with width 3
. All pretty straightforward.
Try it online!
String input
Now we do the "No A. just CAPS LOCK". We repeatedly find strings which are delimited by a
(either case), with no a
in between (with some trickery to make it work for the end of the string as well. We throw away the bounding a
s, and flip the case of the string between the a
s.
Try it online!
Rotating 90° counter clockwise, no mirroring
We then end up with effectively:
if(eof()){{say++$_;redo}}
else{$_=<>;chomp;if(/\D/)
{/^.+?(?{say$&})(?!)/;/^(
..*).(?{say$1})(?!)/x}else
{$p=$_>1;$n=$_;$p&&=$n%$_
for 2..$n-2;say!!$p}}
No input
With no input, we enter an infinite loop, where we increment $_
and print the result.
Try it online!
Integer input (non-negative)
We will now determine whether the given number is a prime number. We do this by checking whether non of the integers between (but not including) 1
and the input number evenly divides the input number. We then print the result (1
if it's a prime, an empty line if it's not).
Try it online!
String input
Now we do the YouTube Comments #1 task. We do this by finding all sub strings of the given string, which are anchored at the beginning. This is done by use a regexp (/^.*?/
), printing the match (/(?{say $&})/
) and then failing the match (/(?!)/
(it can never happen that the current position isn't followed by an empty string)). This cause Perl to backtrack and try the next match. The quantifier modifier ?
makes Perl try the shortest strings first. This takes care of the first half (including the full line). For the second half, we use /^(..*)./
, which does almost the same thing, except it only matches sub strings which are followed by at least one other character (so, it skips the full string), and it tries it in "longest first" order.
Try it online!
Rotating 90° counter clockwise, mirrored
Then we effectively get:
if(eof()){$_=join"",A..Z,
A..Y;/.{26}(?{say$&})(?!)/
;exit}$_=<>;$v=aeiouy;$c=
"[^$v]";$v="[$v]";if(
/^($c*$v*($c))$c*($v)/){
say$1.((({split//,bpcgdtf.
vgkkgpbsztdvfzs}->{$2}||$2
).$3)x 2)}else{@x=(0,1);@x
=($x[1],$x[0]+$x[1])while
--$_>=0;say$x[0]}
No input
This prints out the "Tabula Recta". It does so by creating a string consisting of all the letters A
to Z
, followed by the letters A
to Y
(so, 51 letters in total). We then find all sub strings of length 26 and print them, using the same trick as above.
Try it online!
Integer input (non negative)
In this case, we calculate the N
th Fibonacci number, where N
is the input. We do this by keeping track of two numbers, initialized to (0, 1)
, and N
times replacing (n, m)
by (m, n + m)
.
Try it online!
String input
Now we "Covfefify a string". We start of by grabbing the parts of the string we need (/^($c*$v*($c))$c*($v)/
, where $c
and $v
are character classes matching consonants and vowels). We find the replacement consonant by doing a lookup ({split//,bpcgdtfvgkkgpbsztdvfzs}->{$2}||$2
-- the string is split into a list of characters, the surrounding {}
turns the list into a hash ref; the ->{$2}
indexes the second captures; if there is no match, the ||$2
makes it return the second capture -- this takes care of consonants which are replaced by themselves). Then it's a matter of constructing the final string.
Try it online!
Rotate the program, no mirroring
We effectively end up with:
if(eof()){$_=("___|"x18).$/;$_ x=2;s/^..|..$//g;$_ x=5}
else{@c=map{$_-1}<>=~/./g;$_=$".(""," ___"," _"," ___"
)[$c[0]].$/.$".("_===_","....."," /_\\","(_*_)")[$c[0]]
.$/.($","\\",$",$")[$c[4]]."(".(".","o","O","-")[$c[2]]
.(",",".","_",$")[$c[1]].(".","o","O","-")[$c[3]].")".(
$","/",$",$")[$c[5]].$/.("<",$","/",$")[$c[4]]."(".($".
": ","] [","> <"," ")[$c[6]].")".(">",$","\\",$")[$c[
5]]."\n (".(" : ",'" "',"___"," ")[$c[7]].")"}say;
No input
We now "Build me a brick wall!". We start off by concatenating the string ___|
18 times by it self, adding a newline, then doubling the line. We remove the first two characters, and the last two characters before the final newline. We then print the result 5 times.
Try it online!
Other input
It's time to build a snowman. We split the input on characters (which is assumed to be a string consisting of 1
s, 2
s, 3
s, and 4
s). It's then just a matter of combining the pieces of the snowman by getting the right parts from a series of lists.
Try it online!
Rotated 180°, mirrored.
Effectively, we have:
if(eof()){say$_%15?$_%5?$_%3?$_:Fizz:Buzz:FizzBuzz for
1..100;exit}say<>=~/^8|^1[18](...)*$/?an:a;
No input
Without input, the program does the FizzBuzz challenge. Nothing special going here, we loop numbers from 1 to 100, if 15 divides it evently, "FizzBuzz" is printed; if 5 divides it evently, "Buzz" is printed; if 3 divides it evenly, "Fizz" is printed, else, the number itself is printed.
Try it online!
Other input (assumed to be a non-negative integer)
This does the "You're on a 8 day streak!" task. If the input starts with 8
, or starts with either 18
or 11
followed by 3 k
digits for some k >= 0
, we print "an", else we print "a".
Try it online!
Rotated 270° counter clockwise, no mirroring.
We end up with:
$_="Happy Birt"
."hday to You";
say;say;say
s!to!Dear!r=~
s!You!Perl!r;say;
This does only one thing, sing "Happy Birthday". The string "Happy Birthday to You" is created, and printed twice. Then it's printed with "to" replaced by "Dear", and "You" by "Perl". Then the original string is printed once again.
Try it online!
Rotated 270° counter clockwise, mirrored.
Effectively, we end up with:
$x=(("Baby Shark".(
" doo"x6).$/)x3).Baby.
" Shark!";say$x;say$x
=~s/Baby/$_/gr for
Daddy,Mommy,Grandpa,
Grandma;
This sings Baby Shark. It creates the string "Baby Shark doo doo doo doo\n", repeated thrice, followed by "Baby Shark!". This is printed, then it's printed another four times with Baby replaced by "Daddy", "Mommy", "Grandpa", and "Grandma" repectively.
Try it online!