37
7
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.
Task
Write a polyglot that fits in a single cluster (512 bytes or less) and solves as many of the following tasks as possible.
Read all input and print it.
Print Hello, World!.
Read a line/argument (name) as input and print Happy Birthday, [name]!.
Read all input and print I love tabs! if it contains one or more tabulators (0x09) and I hate spaces! if it doesn't.
Read two lines/arguments and print a truthy value if the second is a substring of the first and a falsy value if not.
Read a line/argument and print a truthy value if its characters are in strictly ascending order and a falsy value if not.
Read a line/argument and a character and print the indexes of all occurrences of that character.
Read a line/argument and print any of the characters with the highest number of occurrences.
Read two integers between 0 and 255 and print their sum.
Read a single integer between 0 and 255 and print the quotient and residue of its division by 7.
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.
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.
Read two integers between 0 and 255 and print the larger one.
Read a decimal integer between 0 and 255 print its hexadecimal representation.
Read a single integer between 0 and 255 and print its Hamming weight (number of 1-bits).
Read a single integer n between 1 and 13 and print the Fn, the nth Fibonacci number.
For example, for the input
13
, print233
.
Read a line/argument of input and frame it.
For example, for the input
Programming Puzzles & Code Golf
, print this:+---------------------------------+ | Programming Puzzles & Code Golf | +---------------------------------+
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 unreadable
Read an integer between 1 and 40 and print a diamond of that side length.
For example, for the input
3
, print this:/\ / \ / \ \ / \ / \/
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).
Additional rules
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) 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 code-golf rules apply.
In particular, this includes the Loopholes that are forbidden by default, with the exception of hard-coding the output, which is explicitly allowed for this challenge.
1Are JavaScript and CoffeeScript different enough to be considered different languages? – Downgoat – 2015-09-15T04:35:44.220
Yes, those count as different. – Dennis – 2015-09-15T04:38:27.963
17your challenge #4 is nonsense >:( – Doorknob – 2015-09-15T11:28:59.317
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. – Cabbie407 – 2015-09-16T05:50:35.3672
@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.
– Dennis – 2015-09-16T05:52:49.980It does? Wow, that's news to me. But okay, I can live with that.
;)
– Cabbie407 – 2015-09-16T05:55:59.627