Overcoming cluster size

Fed up with the reliability of flash storage, you decided to store all your programs on one of those good old 1,440 KiB floppies. However, after copying not even 3,000 programs, the disk was full. How's that even possible? Skilled in the art of code golf as you are, most of your programs aren't even 100 bytes long, so there should be plenty of room left...

After asking about it on Super User, you discover that you have been wronged by the file system's cluster size, an evil plot of the designers of FAT12 that leaves a significant portion of your floppy unused and forces you to buy more than you actually need.

Buy more floppies? Never! Cluster size will be less of an issue if we simply save multiple programs in one file, which is possible because different compilers/interpreters will behave differently for the same source code.

Write a polyglot that fits in a single cluster (512 bytes or less) and solves as many of the following tasks as possible.

1. Read all input and print it.

2. Print Hello, World!.

3. Read a line/argument (name) as input and print Happy Birthday, [name]!.

4. Read all input and print I love tabs! if it contains one or more tabulators (0x09) and I hate spaces! if it doesn't.

5. Read two lines/arguments and print a truthy value if the second is a substring of the first and a falsy value if not.

6. Read a line/argument and print a truthy value if its characters are in strictly ascending order and a falsy value if not.

7. Read a line/argument and a character and print the indexes of all occurrences of that character.

8. Read a line/argument and print any of the characters with the highest number of occurrences.

1. Read two integers between 0 and 255 and print their sum.

2. Read a single integer between 0 and 255 and print the quotient and residue of its division by 7.

3. Read a single integer between 1 and 255 and print a truthy value if it is a composite number (neither 1 nor prime) and a falsy value if not.

4. Read a single integer between 1 and 255 and print a truthy value if it is a power of 2 and a falsy value if not.

5. Read two integers between 0 and 255 and print the larger one.

6. Read a decimal integer between 0 and 255 print its hexadecimal representation.

7. Read a single integer between 0 and 255 and print its Hamming weight (number of 1-bits).

8. Read a single integer n between 1 and 13 and print the Fn, the nth Fibonacci number.

For example, for the input 13, print 233.

1. Read a line/argument of input and frame it.

For example, for the input Programming Puzzles & Code Golf, print this:

+---------------------------------+
| Programming Puzzles & Code Golf |
+---------------------------------+

2. Read a rectangular block of characters and rotate it a quarter turn clockwise.

For example, for the input

 tye
xll
epb
tma
id
sa
s e
i r
hsn
Tiu


print this:

 This  text
is  simply

3. Read an integer between 1 and 40 and print a diamond of that side length.

For example, for the input 3, print this:

   /\
/  \
/    \
\    /
\  /
\/

4. Print this:

 ....@@@@....@@@@....@@@@....@@@@
....@@@@....@@@@....@@@@....@@@@
....@@@@....@@@@....@@@@....@@@@
@@@@....@@@@....@@@@....@@@@....
@@@@....@@@@....@@@@....@@@@....
@@@@....@@@@....@@@@....@@@@....
....@@@@....@@@@....@@@@....@@@@
....@@@@....@@@@....@@@@....@@@@
....@@@@....@@@@....@@@@....@@@@
@@@@....@@@@....@@@@....@@@@....
@@@@....@@@@....@@@@....@@@@....
@@@@....@@@@....@@@@....@@@@....
....@@@@....@@@@....@@@@....@@@@
....@@@@....@@@@....@@@@....@@@@
....@@@@....@@@@....@@@@....@@@@
@@@@....@@@@....@@@@....@@@@....
@@@@....@@@@....@@@@....@@@@....
@@@@....@@@@....@@@@....@@@@....
....@@@@....@@@@....@@@@....@@@@
....@@@@....@@@@....@@@@....@@@@
....@@@@....@@@@....@@@@....@@@@
@@@@....@@@@....@@@@....@@@@....
@@@@....@@@@....@@@@....@@@@....
@@@@....@@@@....@@@@....@@@@....


Scoring

The answer that manages to incorporate the highest number of programs in a single file that fits in a single 512-byte cluster wins. Ties are broken by byte count (lower is better).

• For each task you claim for your score, the same file (byte per byte) must constitute a full program – in a language of your choice – that solves this particular task.

• Each task has to be solved in a different language.

Languages count as different if they are not different versions of the same language. For example, there's only one JavaScript, one Python and one TI-BASIC, but C, C++, Octave and MATLAB are four different languages.

• The selected language for each task has to satisfy our usual definition of programming language.

In addition, the language must have been published and implemented before September 9, 2015.

• Your compiler/interpreter may not require any non-standard flags to produce the expected behavior.

Exceptions to this rule include flags required to specify a particular language, to read the program from a (single) file or to suppress a banner.

• The input for each task will consist of printable ASCII characters (0x20 to 0x7E), tabs (0x09), and linefeeds (0x0A), and it will not exceed 255 bytes in length.

• All integers can be read in decimal or unary, unless stated otherwise in the task.

• Behavior for invalid input is undefined.

• You may read input from STDIN (or its closest alternative) or as command-line arguments.

If a task requires reading two pieces of input, you can read them – in any order – separated by a one-byte delimiter of your choice, as separate command-line arguments or one from STDIN and the other as command-line argument.

If one of the input pieces is a line, the only possible delimiter is a linefeed.

• Print the output to STDOUT (or closest alternative). All output to STDERR will be ignored.

• For each task, standard rules apply.

In particular, this includes the http://meta.codegolf.stackexchange.com/q/1061, with the exception of hard-coding the output, which is explicitly allowed for this challenge.

• Are JavaScript and CoffeeScript different enough to be considered different languages? Sep 15 '15 at 4:35
• Yes, those count as different. Sep 15 '15 at 4:38
• your challenge #4 is nonsense >:(
– Doorknob
Sep 15 '15 at 11:28
• Quote: All output to STDERR will be ignored. Does this mean that when we call the script/program with 2>/dev/null and get the correct output to stdout, it is okay? Just to be sure. Sep 16 '15 at 5:50
• @Cabbie407 Precisely. Per consensus on meta, this rule actually applies by default to all challenges. I just wanted to make sure that everybody was aware of it. Sep 16 '15 at 5:52

12 languages, 418 bytes

"1\"# &&+.@\""" "" "
#=
''''
<<s
""'("']0=~2base{+}*}
?
:_7/!\_7%!@
"
R"Happy Birthday, "[?S"!"*"
>0[0>i:0(?v:{)?v0n;\!/
$'main';n1< .95< \@-[I love tabs!]o# \ >qi---@ ( @-[ ]e<''';print hex( input())#-[I hate spaces!]o#"]];ri:X{_~X+S*'/@S*_'\4$N}%_sW%1>"))?(!?)
#=
Tr is here.
>Tr, Hello, World!
>X Tr
s
l=gets
a='+-'+?-*~/$/+'-+' puts a+' | %s | '%l+a#=#.91<0#'''#";  This is a fun challenge. It's getting hard to fit more languages in, but with this many bytes left I could probably do about one more. Makes gratuitous use of 2D languages. Note that the char on between the [ ] on the @-[ ]e< line is a tab. Also, this requires \n line endings for TRANSCRIPT to work. Prelude (Task 1 / Cat) ( )?(!?)  ?(!?) is just a direct translation of ,[.,] in BF. Prelude () loops act like BF [] loops, so everything from the ( in the leftmost column to the ) before the core program is unexecuted. Prelude's syntax rules mean that parentheses need to be matched (reading left-to-right column-wise), and there can only be one parenthesis per column. Other than that, it's a pretty easy language to fit in. Make sure NUMERIC_OUTPUT is set to False if you're using the Python interpreter. TRANSCRIPT (Task 2 / Hello world) Tr is here. >Tr, Hello, World! >X Tr  TRANSCRIPT is a thematic esolang based on interactive fiction. Lines not recognised by TRANSCRIPT are ignored, making it easy to fit in. Tr is here. declares a Tr string variable, and the second line sets the contents of the variable to Hello, World!. X Tr (X for examine) then outputs the string. Although TRANSCRIPT is very easy to fit in, it's a pretty verbose language, so I made it take the easiest challenge. Fission (Task 3 / Birthday message) R"Happy Birthday, "[?S"!"* \!/  which prints the first part, cats the input with a small 2D loop, then outputs the trailing exclamation mark. The R signifies that an atom starts here moving rightward, which is useful because this program can be moved around anywhere. Rail (Task 4 / Tabs) $'main'
\@-[I love tabs!]o#
\ >qi---@
@-[ ]e<
-[I hate spaces!]o#


Like Fission, Rail is a 2D language which has the advantage of being able to be moved around anywhere. Execution starts from the $ of the main function, heading southeast. First we head down the \s, turn left at -, hitting [<tab>] which pushes a tab. e< then branches based on EOF – if EOF, we head down and print "I hate spaces!" before halting, else we head up. If we headed upwards, we read the next char and compare it with the tab, once again branching – if tab, head up and print "I love tabs!" before halting, else head down and continue the input loop. This program is pretty expensive, but since TRANSCRIPT took Hello World it was hard to pick and appropriate task for Rail. ><> (Task 6 / Ascending input) "1\"# \""" "" " >0[0>i:0(?v:{)?v0n; ;n1< .95< .91<  Prints 1 if strictly ascending, 0 otherwise. ><> is another 2D language, and execution starts from the top left. "..." is string mode, pushing the inner chars one at a time. After the first string we hit #, which reflects the IP leftward, pushing more strings and wrapping around (><> is toroidal) before hitting \, a mirror which reflects us upwards. At the bottom of the program is .91<, which teleports us to (9, 1), where the core program is. After this 0[ removes all the junk from the strings, 0 pushes a zero to represent the last char read, and after this it's just reading chars one at a time, making sure we're still ascending. It's probably better to move the core program down instead of teleporting, but I'll deal with that later if necessary. Befunge (Task 9 / Addition) "1\"# &&+.@  Tested with the interpreter found here. This is a pretty straightforward program, with the start pushing a useless string and # jumping over the space. After that it's just the core program &&+.@. Labyrinth (Task 10 / Divmod by 7) "1 = ' < ""'("'] ? :_7/!\_7%!@  Conveniently, ' and " are NOPs in Labyrinth which act like a walkable path in the maze. I'll skip the messy navigation, but basically there's a lot of turning and wandering around going on before we hit the ?, which is the start of the core program. The program is not quite flush left to account for Prelude (e.g. ? is read input in Prelude). Python 2 (Task 14 / Hexadecimal) "1\"# &&+.@\""" "" " #= '''' xxx xxx''';print hex( input())#xxx ''' xxx xxx'''#";  The xxxs represent irrelevant portions commented out by multiline strings or comments. In between is print hex(input()), the core progam. This outputs with a leading 0x, but I'm assuming that's okay (if not, then it's an easy fix anyway). The first line is a string "1\"# &&+.@\"" followed by two " "s. These three strings are concatenated by the parser, and left unused (this first line works similarly for Ruby and Julia later). GolfScript (Task 15 / Hamming weight) "1\"# &&+.@\""" "" " #= '''' <<s ""'("']0=~2base{+}*}  The first line pushes three strings, and the second line is a comment. '''' pushes two more strings, then << does two comparisons (s is ignored). Finally, ""'("' pushes another two strings. All of this is junk is then removed by wrapping it in an array and getting the first element (]0=), which is the input initially on the stack. We then evaluate the input with ~, turn into binary with 2base then sum the bits with {+}*. The next } is unmatched, and super-comments the rest of the program. Julia (Task 16, Fibonacci) "1\"# &&+.@\""" "" " #= xxx xxx=#print(([1 1;1 0]^int(readline()))[1,2]) #= xxx xxx=#.91<0#xxx  #= starts a multiline comment and =# ends a multiline comment. The core program uses matrix exponentiation to calculate Fibonacci numbers (taken from Rosetta). Ruby (Task 17 / ASCII frame) "1\"# &&+.@\""" "" " #= '''' <<s xxx s l=gets a='+-'+?-*~/$/+'-+'
puts a+'
| %s |
'%l+a#xxx


This program assumes that the input does not end with a trailing newline.

We have a useless string, a comment, another useless string then a heredoc which comments out most of the program. After that is the core program, followed by a single line # comment.

"1\"# &&+.@\""" "" "
#=
''''
<<s
""'("xxx
"
R"xxx"[?S"!"*"
xxx
xxx"ri:X{_~X+S*'/@S*_'\4$N}%_sW%1>"xxx xxx xxx";  The two space strings at the end of the first line are to satisfy CJam, since #= are two binary operators. I won't go into too much detail with this one, but basically it's a mess, with the core program being the mere ri:X{_~X+S*'/@S*_'\4$N}%_sW%1>


in between.

The key differentiator between GolfScript and CJam is that, in CJam, a single quote ' doesn't start and end strings, but instead pushes the next character to the stack. This means that in CJam

'("'


pushes a ( then starts a string with " (the first char of which is '), whereas the above is just a straight single string in GolfScript.

Try it online. 1> is used instead of ( to account for Prelude.

Here's 12 languages, 373 bytes. Some tasks have moved around, TRANSCRIPT has been removed (it made Rail too expensive) and Scheme (chicken) has been added. This is just my golfing ground for to-be updates since updating the main post takes forever.

"1\"09!#.&&+.@"" "" "#|"
#=
''''
<<s
11]0=~2base{+}*}
?
:_7/!\_7%!@
"
R"Happy Birthday, "[?S"!"*"
>0[0>i:0(?v:{)?v0n;\!/
$'main';n1< .95< (-[Hello, World!]o#''';print(input()in input());'''"]];ri:X{_~X+S*'/@S*_'\4$N}%_sW%1>"=#print(([1 1;1 0]^int(readline()))[1,2])#=)?(!?)
s
l=gets
a='+-'+?-*~/$/+'-+' puts a+' | %s | '%l+a# =##'''#";e# |#(print(format"~x"(eval(read))))  I could save a few bytes for Julia since unterminated multiline comments raise an error to STDERR. • Great stuff. What's the task for TRANSCRIPT? Sep 27 '15 at 8:37 • @Cabbie407 I'm still trying to optimise which language gets which task, but currently TRANSCRIPT has taken Hello World, and Rail has changed to the tabs task. Sep 27 '15 at 8:39 • Ah, now I can see it ;) I'm procrastinating changing anything in my answer, because of the long description. lol Sep 27 '15 at 8:46 789 10 languages, 398431447 507 bytes This is probably the most I can fit in the current solution. #if + 0+0/*^",v +- '[.,][[" ,yadhtrib yppaH"l?!;offf4+ + +0.0 +aa<*/ a=0--0;b=input();print(sorted(set(b))==list(b));[["""" ^ < print("Hello, World!")--[[vv? +< #endif/* >.!0 + +1ffr"!"~< */ #include<stdio.h>/*>:1 +?!^>i:1^*/ int main(){int a=1,b=1,c,i;scanf("%d",&i);if(1//**/1==2 ){printf("%x",/*>&:7/.7%.@*/i);}else{for(;--i-1>0;a=b,b=c)c=a +b;printf("%d",b);}}/*]]--"""]];#@;_J + + \+*\-hhlz \+s[\|dzd\|)J " + +,*.]]]*/SSSTNSSNSNSTNTTTTTSSSTNSNSTNTTTTTTSSTNTTSNSSNNSSSNTTTTNSTNNNN  The last line contains Whitespace code encoded so that SE doesn't eat it. To run the code, replace all S with spaces, T with tabs and N with newlines. C89, task 16 Here's what the compiler sees: int main(){int a=1,b=1,c,i;scanf("%d",&i);if(1/ 1==2 ){printf("%x",i);}else{for(;--i-1>0;a=b,b=c)c=a+b;printf("%d",b);}}  Everything else is stripped as comments or inside the #if 0. C++, task 14 I used a trick stolen from here to differentiate between C89 and C++. int main(){int a=1,b=1,c,i;scanf("%d",&i);if(1 ){printf("%x",i);}else{for(;--i-1>0;a=b,b=c)c=a+b;printf("%d",b);}}  Lua, task 2 Here's the basic structure. #comment a=0--comment print("Hello, World!")--[[ ... multiline comment ... ]]--comment  Brainfuck, task 1 I just had to ensure no infinite loops or stray .,s are found. Lua's multiline comments also double as BF comments. Everything apart from the first 2 characters is a large NOP loop. ++,+-[.,][[,+++.+<--[[<,--[[+<>.++<<.>>+>,,,,,>..--->,+,]]--]]+++-+[++,.]]]  Python, task 6 Again, I'm using language-specific features to NOP or comment out the other code. #comment a=0--0;b=input();print(sorted(b)==list(b));[[""" ... multiline string ... """]];#comment  Pyth, task 17 Pyth is nice for this thing. It takes the first # as a while True: loop that exits silently on error. So, I just make most of the code a string (as to avoid ;s ending the loop early), then just end the loop, exit another created by the Python comment and do the task. Here's it with all non-empty strings replaced with " string ", it's still functionally equivalent: #if + 0+0/*^" string " ,yadhtrib yppaH" string """" string "Hello, World!" string "!" string "%d" string "%x" string "%d" string """]];#@;_J + + \+*\-hhlz \+s[\|dzd\|)J " string  ><>, task 3 This one is very interesting. The execution bounces around in the code, using jumps where necessary to get around obstacles. The relevant parts: # v " ,yadhtrib yppaH"l?!;offf4+ + +0.0 +aa<*/ i ^ < ! vv? +< >.!0 + +1ffr"!"~< >:1 +?!^>i:1^  Starry, task 9 Here I had to start going into the "discard all characters except " languages. Anything else stripped out, it looks like:  + +*, + '., , + + +. +* , +* . + + *.* +* ,,,,**,*..*, +,* + + +* +  + +,*.*  The code skips most of the punctuation with a jump to avoid a hard time, just using the start and end of the code. The code is functionally equivalent to  + +*, + + +,*.*  Befunge-98, task 10 Works similarly to the ><> one. Luckily, # is a mirror in ><> and a skip in Befunge, so we can implement different behavior. Also, 0/0 == 0. #if + 0+0/*^ >&:7/.7%.@  Whitespace, task 13 This was the last thing I fit in. The first few lines are just pushing zeroes onto the stack, as they only contain spaces and newlines from the "normal" code. The code is encoded; replace all S with space, T with tabs and N with newlines. SSSSSSSSSSSSSSSN SSSSSSSSSSSSSSSSSSN SSN SSSSSN SN SSN SSSSSSSSSSSTN SSN SN STN TTTTTSSSTN SN STN TTTTTTSSTN TTSN SSN N SSSN TTTTN STN N N  17 different versions of Pip, 383 bytes (invalid) While this question was sandboxed, I combed through all the revisions of my language Pip and came up with a polyglot using 17 of them. Sadly, versions of the same language are disallowed by the challenge rules now, but with Dennis's permission and a disclaimer I'm posting my work anyway. The raw code I!ga:0m@0:0v:uIN[(oTM0,0i)EN1N1Y1RCkw(hR1.+0&2o)@>3@AB0urZ4AB6({a}V7)BN8AZ9@m]Iv<2W##YqlPByc:((J['.'@]X4)X4RL3)Jnc.:n.RVcc:cRL4|0Iv=3{d:sXaRLaFj,ad@j@j:'\d:(RVdR'\'/).d|0dJ:n}m:'+.'-X#a+2.'+.n."| "Iv=5La{i+:oSio}j:ak:bPv=11?a>1&0INa%(2,a)[((J_M ZRVl)|0)Jnl?lJnlcJnd.n.RVdm.a.RVmih:$+TBa({j@aEQk}FI0,#a).saTB16a>b?abh=1ua//7.s.a%7a+bbINa"Happy Birthday, ".a.'!"Hello, World!"]@v


The strategy

In Pip, lowercase letters are variables. Uppercase letters are more complicated: they are broken into runs of at most two characters, which can be operators or variables. If an uppercase token isn't specifically defined as a variable or operator, it is assumed to be an undefined variable, which evaluates to nil.

So, to distinguish between two versions of Pip, I just have to find some variable or alphabetic operator that was added in the newer of the two. In the older one, it will be nil instead. The code v:uIN[...] puts together a big list containing one of these checks for each version I want to test, finds out how many nils are in that list (the u variable is explicitly initialized to nil), and stores the number in v (for "version").

After some other calculations, there's another big list that calculates the results for 17 of the tasks from the challenge and uses v to select one based on what version this is.

0.15.09.04

Diagnostic: (oTM0,0i) (fixed a bug with TriM operator where trimming 0 characters from each end of a string would give the empty string instead; indexing into empty string gives nil)

Task 18: Iv<2W##YqlPBy (setup: read all lines from stdin if v is less than 2) followed by ((J_M ZRVl)|0)Jn (reverse list of lines, transpose, and join back into string)

0.15.08.06

Diagnostic: EN1 (added ENumerate operator)

Task 1: Iv<2W##YqlPBy (same setup code as above) followed by l?lJnl (join on newlines)

0.15.08.03

Diagnostic: 1N1 (added N as short version of IN operator)

Task 20: c:((J['.'@]X4)X4RL3)Jnc.:n.RVcc:cRL4|0 (setup: generate list containing upper and lower halves of chessboard and store in c) followed by cJn (join on newline)

0.15.08.01

Diagnostic: Y1 (added Yank operator)

Task 19: Iv=3{d:sXaRLaFj,ad@j@j:'\d:(RVdR'\'/).d|0dJ:n} (setup: if v is 3, build top half of diamond in d) followed by d.n.RVd (reverse for bottom half and join on newline)

0.15.06.19

Diagnostic: RCk (added Random Choice operator)

Task 17: m:'+.'-X#a+2.'+.n."| " (setup: build +----+\n|  string in m) followed by m.a.RVm (wrap input in m and reverse of m)

0.15.06.12

Diagnostic: k (preinitialized k variable to ", "; previously it was undefined and thus nil)

Task 16: Iv=5La{i+:oSio} (if v is 5, generate Fibonacci number in i) followed by i

0.15.06.08 (note: version number wasn't changed till the following commit)

Diagnostic: w (preinitialized w variable to \s+)

9. Befunge-93

/&&#[+.#]@


As I understand it, / divides the stack and pushes the result which has no ill-effects except pushing NaN on the above site, & asks for input of an integer so we read both numbers required by challenge 9 onto the stack, the # ensures we skip over the [ which is there for brainfuck, + then adds the top two numbers on the stack, . outputs them, #] for brainfuck again and @ exits.

13. PHP (running in Bash)

/&&#[+.#]@>>+[>,]<[<]>>[.>]>\[/;//;#<?die("\x1bc".max($argv[1],$argv[2]));


Usage:

php cluster <x> <y>


In PHP, anything not included within the <? tags is output verbatim, so this outputs the Befunge-93 and brainfuck code so we die() immediately in the code, output a screen clear (\x1bc) then the max() of the first two arguments.

• You can put the literal ESCape character in the string literal, just add a note that it's there (the first character in the first string literal is the byte ASCII 27); your score is 226.
– cat
Apr 20 '16 at 15:37
• @cat Yeah, I think you're right, I've left as-is for now, but I did put 226 in the title. I've forgotten how much I enjoyed this challenge, I could probably do a bit more now and using ES6 I could have .match'\x09' (where the ' are ) maybe I'll see if I can add more at some point! Apr 20 '16 at 16:19

6 languages, 450 404 bytes

bash, brainfuck, C, gawk4, JavaScript and Minimal-2D

/*\t/#[R,+/D
/\t/ # UL.-L<script>var s=prompt().split(' ');alert(+s.pop()+ +s.pop())</script>
sed "s/^$$.*$$$/Happy Birthday, &!/;q"&&0 /\t/#*/ #define func func main(){puts("Hello, World!");} //{split($0,b,_);for(i in b)a[NR][i]=b[i++]}END{for(;j++<i;print"")for(k=NR;k;)printf a[k--][j]}
#//]++++++++[>+>+>++++++>++++++++<<<<-]>>++>--<<[>>>>>+++[<++++[<<....>....>-]<<<.>>>>-]<<<[>>+<<-]<[[>+<-]<]>>-]


Update: Golfed it down a little. Still not sure what else to add, and I'm not sure how the competing members would think about me using their languages for different tasks. Trying to explain the brainfuck algorithm.

Well this is/was my first polyglot experience, so I had to learn everything from scratch. Starting with awk was not the smartest idea I think, because it is relatively unforgiving. Because the number of completed tasks is relevant I started with the easiest tasks first. Not sure if that was a smart move. This is not very much golfed, because I had enought trouble getting these six working together, but I did what I could to keep it short.

Here are the languages and what they do in alphabetical order. I'll show an easy way to test them all further down. Because some of this might be version specific I'll give you the version numbers of the tools I used.

Well, its obvious that I used sed. I tried to put a sed script in this somehow, but I couldn't get it to work, so I went the bash route. The way I dit it, it is inside a C comment and awk evaluates it to False.

sed --version gives sed (GNU sed) 4.2.2

bash --version gives GNU bash, Version 4.3.30(1)-release (x86_64-pc-linux-gnu)

So the sed part comes down to

sed "s/^$$.*$$$/Happy Birthday, &!/;q"  It groups the input, pastes it into a new string and prints the result. Pretty common stuff. brainfuck, task 20 Well this is always pretty easy to hide I guess. A line starting with #// is ignored by C and awk. Or at least they can live with rubbish behind that. bf gives bf - a Brainfuck interpreter version 20041219 This is the condensed code. The first line is only the garbage from the other languages. [,+.-<>.+.++.<>.,,,,[][][++]++<[--][]] ++++++++[>+>+>++++++>++++++++<<<<-]>>++>--<< [>>>>>+++[<++++[<<....>....>-]<<<.>>>>-]<<<[>>+<<-]<[[>+<-]<]>>-]  I'll try to explain how it works ++++++++[>+>+>++++++>++++++++<<<<-]>>++>--<<  this arranges the tape and pointer to this 0 8 10 46 64 C2 C1 ^  the cell holding 8 is the global counter for the following loop it's the number of times 3 same lines are printed [>>>>>+++  sets C1 to 3, the number of same lines  [<++++  sets C2 to 4, the number of "....@@@@" in a line (in the beginning)  [<<....>....>-]<<<.>>> >-]  prints a complete line decrementing C2 in the process when C2 is zero it prints a newline and decrements C1. if C1 is zero the magic happens  <<<[>>+<<-] <[[>+<-]<]  the 46 is moved behind the 64 the 10 and the global counter are moved one to the right >>-]  then the global counter is decremented if it's zero the program exits C, task 2 I exhaust every last little ability of C here by printing "Hello, World!". Well, somebody had to do the job... gcc --version gives gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2 The actual C code #define func func main(){puts("Hello, World!");} #  The #define func is to make awk okay with this. It thinks this is an awk function. Abbreviation to func is a gawk feature. gawk4, task 18 Since I have used awk for pretty much everything on here, I decided, that it had to be in this. awk --version gives GNU Awk 4.1.1, API: 1.1 (GNU MPFR 3.1.2-p11, GNU MP 6.0.0) awk sees this /*\t/ /\t/ sed "s/^$$.*$$$/Happy Birthday, &!/;q"&&0
/\t/
func main(){puts("Hello, World!");}
//{split($0,b,_);for(i in b)a[NR][i]=b[i++]}END{for(;j++<i;print"")for(k=NR;k;)printf a[k--][j]} #  The search patterns including \t evaluate to false. I chose tab here, because I think it can't be in the input. sed evaluates to false. "the string"&&0 evaluates to false. The function is okay. The program is executed if an empty pattern is matched, which it is for any input. It does this Input elaic parli ucfit srigs  Output supe rcal ifra gili stic  You have to make sure all the input lines have the same length. Use spaces to fill them up. JavaScript, task 9 I'm not sure if this is legit, because this was too easy. If you give the program file a html ending, and open it in a browser (I used Firefox 40.0.3 and chrome 45.0.2454.85) it prompts you for an input. You have to enter two numbers separated by space, and it will alert the sum of those. <script>var s=prompt().split(' ');alert(+s.pop()+ +s.pop())</script>  Minimal-2D, task 1 This was pretty easy to fit into comment lines. I used the interpreter, who runs in python, to test this. It prints the input to the output. The program looks like this R,+/D UL.-L  R U D L are right, up, down and left. So it starts going right, reads a character from stdin into memory and adds one. The slash skips the next command if the memory has the value 0. This is to end this. If a character with value -1 is read, the input has ended. So if -1 is read it skips the D and terminates. If something else is read it goes down an left, adds that 1 back to the memory and prints the character to stdout. Then it goes left and up and starts over. Testing Disclaimer: I won't take any responsibility for any damages you do to your system with this. This is assuming you have bash & co, gawk (at least version 4, because this uses multidimensional arrays), gcc, python, bf as a brainfuck interpreter and Firefox installed. To make it easy, copy the program source to a file named cluster.html. Make that file executable for the bash task. Copy and paste the interpreter for Minimal-2d into a file named minimal2D.py in the same directory. Then copy and paste the following script to a script file and put it into the same directory, make it executable and run it... well, who am I talking to. If you read this you probably don't need that much explanation and are gonna get it to run somehow anyway. #!/bin/bash # Task 3: bash echo "Dr. Hfuhruhurr" | ./cluster.html 2>/dev/null;echo # Task 18: awk printf "elaic\nparli\nucfit\nsrigs\n" | awk -f cluster.html 2>/dev/null;echo # Task 2: C cp ./cluster.html ./cluster.c;gcc -w -o cluster cluster.c;./cluster;rm cluster cluster.c;echo # Task 1: Minimal-2D python minimal2D.py cluster.html <<<"This has to be copied !!!";echo # Task 20: brainfuck bf cluster.html;echo # Task 9: JavaScript firefox cluster.html 2>/dev/null #google-chrome cluster.html 2>/dev/null  In there you also find the command for running the tests individually. Have fun! • The brainfuck one has a problem; the code has unbalanced brackets and won't run correctly (you have to run the whole file, not just the relevant part). Also, the checkerboard's squares are actually 4x3 instead of 4x4 to look more square in text. Sep 16 '15 at 20:12 • Thanks for the hint. Well it runs fine here. I always run the whole file as you can see in my script. Not sure if the interpreter should check the brackets before running. Mine doesn't mind. But I overlooked that line count. Got to change that. Sep 16 '15 at 20:19 • Well I looked into it again and I hope I fixed it. Sep 16 '15 at 20:39 14 15 languages, 487 bytes brainfuck, Thue, Fission, Rail, Perl, ><>, Surface, Whitespace, Gol><>, Befunge-93, Hexagony, Python 3, PingPong, Cardinal, Ruby #\&v/,[.,][ .hzPSIv?:< #!oan-2l.1*8=;?(1:i::< # :< /2_0#!x%x2$:_.#-@#1:
#>,>, 	\
#	o->+o
#/o?  </
#>:@

#.....\?{?'-~^!@0!;J$?0J$ " ,yadhtriB yppaH"L
print	([]and(0and("#{a=$<.map(&:chars);a[-1].zip(*a).map{|z|z[1,10].reverse*''}*$/}")or"@{[1+index<>,<>]} ")or	0x0or'%x'%(0x0+int(input())))
__DATA__=1
+1;"""
@.<x
v: %+v
>-\*<<
^?/~^
m::=~Hello, World!
::=

$'main'-\ @-[ ]e</i-@ >qfq--[I hate spaces!]o @-[I love tabs!]o  Try it online! 5. Perl This is part of a smaller polyglot with Python and Ruby. Generally, [] is truthy in Perl and Ruby but not Python, and 0 is truthy in Ruby but not Perl. This checks the index of one input in another, and adds one to the result to make it 0 for falsey and a positive number for truthy. This is enclosed in a string interpolation to avoid syntax errors with Ruby and Python. We also have the __DATA__=1 line to prevent it from parsing further than that. print "@{[1+index<>,<>]} "  Try it online! 6: 7: ><> This takes input of the character through the command line and the string through STDIN. This first reflects of the first #, then uses v?: to distinguish between this and Gol><>. This goes down to the second line and loops over the input, checking each character against the command argument, printing the stack height if so. # v?:< !oan-2l.1*8=;?(1:i::<  Try it online! 8. 9. Surface Surface is a 2D language ignoring characters it doesn't recognise. It reflects off the \ and reads the input numbers into two cells with >,>,. Next it enters a loop, decrementing one number and incrementing the other, exiting once one reaches zero. Finally it prints the resulting cell as number.  \ >,>, \ o->+o /o? </ >:@  Try it online! 10. Whitespace This one is rather hard to see, but it essentially executes the instructions: push 32 (SSSTSSSSSL) dup (SLS) dup (SLS) readi (TLTT) (saves to heap at 32) retrieve (TTT) (retrieves from 32) dup (SLS) push 7 (SSSTTTL) div (TSTS) printi (TLST) swap (SLT) printc (TLSS) push 7 (SSSTTTL) mod (TSTT) printi (TLST)  Try it online! 11. Gol><> This follows a similar path to ><>, diverging at the behaviour of ?:, since popping the stack results in 0. It then executes read input as number (I), is it prime (SP), is it zero (z), halt and output (h). # hzPSI ?:<  Try it online! 12. Befunge-93 This interprets # as a skip instead of a reflect, taking input (&) and going down at the v then to the third line. This interpreter ignores invalid characters, skipping past the a and the pair of xs later. This divides the input by two until either it is odd or it is one, and then outputs accordingly (I could probably simplify this check couldn't I?). # &v # :< /2_0#! % 2$:_.#-@#1:


Try it online!

13. Hexagony

Hexagony has a strange path, with the second character being a \, but it eventually ends up at after the ..... on the tenth line. Here it gets the inputs into adjacent edges (?{?), then subtracts one from the other ('-~), and then navigates based on whether that is negative, printing the larger one and terminating (^!@). Note that Hexagony appears to have a bug where a number cannot be the first input without a space before it.

 \

\?{?'-~^!@


Try it online!

14. Python 3

This is pretty a simple task in Python ('%x'%int(input())), but made more complicated by the %s spawning Cardinal pointers. We compensate for these with xs sprinkled in liberally.

print(0x0or'%x'%(0x0+int(input())))


Try it online!

15. PingPong

PingPong skips over the \ with the initial #, wrapping to the bottom at the /. This goes to the bottom of the code, and enters the loop there, continuly integer dividing by two and summing the modulo by 2 until the input reaches 0. Then it outputs the sum it has collected.

#  v/

...

'+\@:+/=
2% ^/*;#\


Try it online!

16. Cardinal

Cardinal is a bit of a pain, since it initially spawns pointers at all %s, which usually need to be squashed with xs. The one we do use in near the bottom, in the string literal. This spawns two pointers, one which collects the input and decrements until it reaches zero, and one that is continually generating the fibonacci numbers by flipping its two values and adding them. Once the first pointer reaches zero it is destroyed by the ?, leading to the second pointer being reflected upwards into the . < to be printed.

. <x
v: %+v
>-\*<<
^?/~^


Try it online!

18. Ruby

Probably the language with the most code, this takes place in a string interpolation as usual. This splits up the input into a 2D array, then zips and joins them together in reverse to produce the transposed output.

print "#{a=$<.map(&:chars);a[-1].zip(*a).map{|z|z[1,10].reverse*''}*$/}"
`

Try it online!

Future work

I'll need to find some new languages to work in there, hopefully 2D languages with arbitrary starting points. Challenge 6 should be pretty easy for any simple language, 8 is a bit tougher. 17 should be achievable with a practical language, 19 and 20 may have to use a golfing lang of some sort to be able to fit within the remaining space. To add more than just challenge 6, I might have to replace some of the longer languages and shuffle them around.