Your boss just emailed you a list of 12 programming tasks he needs done as soon as possible. The tasks are simple enough but your boss, being a young software tycoon suckled by social networking, insists that your solutions be able to fit within a single Twitter tweet.
This means that you only have 140 bytes worth of code to solve all the tasks, an average of 11.67 bytes per task. (Yes, Twitter counts characters but your boss specifically said bytes.)
You realize there's no way to solve all 12 tasks in 140 bytes but you suspect that your boss won't actually test all your solutions. So you proceed to solve as many tasks as you can, completely skipping some of them. Your mindset is that it doesn't matter which subset of the tasks you complete, it only matters that the subset is as large as possible.
How many tasks can you complete?
Challenge
Write up to 12 different programs, each of which accurately solves one of the 12 tasks listed below. The cumulative sum of the lengths of these programs may not exceed 140 bytes
Alternatively, you may write a single program no greater than 140 bytes long that takes an integer from 1 to 12 and (ideally) proceeds to solve the corresponding task, taking more input as necessary. Not all the tasks need to work, but only the ones that do count towards your score. Tasks that don't work are allowed to error or do anything else.
In either case a "program" may in fact be a function that takes the input as arguments or prompts for it and prints or returns the output. So, for example, you might write a 140 byte function that looks like f(taskNumber, taskInput)
, or you might write separate code snippets for each task, some as functions and some as fully-fledged programs.
Other details:
All code must be written in the same language.
As usual, input should come from stdin, the command line, a function argument, or whatever is usual for your language. Output is printed to stdout or your language's closest alternative, or returned in an appropriate type.
A reasonable amount of input formatting is fine; e.g. quotes around strings or
\n
instead of actual newlines.Output should be exactly what is called for with no extraneous formatting or whitespace. The exception is an optional single trailing newline.
Code that only runs in a REPL environment does not constitute a program or function.
You may not write multiple programs that solve multiple tasks. It's either one program that (ideally) solves all the tasks, or (ideally) 12 programs that each solve a single task.
Posting a task solution that you didn't write or only slightly modified is not allowed without giving attribution to the original author, and ideally getting permission too. If your answer primarily composes the shortest solutions from all the other answers then it should be a community wiki.
Scoring
The submission that completes the most tasks is the winner. If two submissions tie, the one with the fewest bytes wins. If the byte counts are tied, the earlier submission wins. Community wiki answers are not allowed to win.
Be sure to tell us which tasks you solved, not just how many!
Handicap for non-golfers:
It's likely that this challenge will be dominated by golfing languages. Many languages may have trouble solving even one or two tasks within 140 bytes. Therefore you may submit a non-competitive answer where the limit is 3 tweets, i.e. 420 bytes. All the other rules remain the same.
Tasks
Task 1 - Can Three Numbers Form A Triangle?
Take in three positive integers and output a truthy/falsy value indicating whether or not three lines with those lengths could form a triangle. You may not assume the numbers come in any particular order.
Truthy examples (one per line):
20 82 63
1 1 1
2 3 4
1 2 2
Falsy examples:
6 4 10
171 5 4
1 1 2
1 2 3
Task 2 - Closest To One Million
Given a string of exactly 7 decimal digits (0-9), rearrange them to get a number that is as close as possible to one million. That is, abs(1000000 - rearrangedNumber)
should be minimized.
Print or return the resulting number as an integer, not a string (so there shouldn't be leading zeroes unless that's the norm for your language).
e.g. an input of 9034318
should result in 984331
(and not 1033489
).
2893984
should become 2348899
.
0001000
should become 1000000
.
0000020
should become 200000
.
Task 3 - Simple Keyboard Simulator
Take in a string of lowercase letters (a-z), spaces, and angle brackets <>
. Read left to right, this string represents the keys that were pressed on a standard keyboard while an initially empty text editor was open. The letters and space correspond to their normal keys but <
corresponds to the left arrow key and >
to the right arrow key, both of which move the cursor when pressed.
<
moves the cursor one character left, or does nothing if the cursor is at the start of the string.
>
moves the cursor one character right, or does nothing if the cursor is at the end of the string.
Output the string that would be in the text editor once all the keys in the input string have been pressed. Outputting escape codes to move the cursor is not allowed.
There will always be at least one non–arrow key character in the input.
e.g. the input ui<<q>>ck <<<<<<the<<<<>>> >>>>>>>>brown x<o<f
should yield the quick brown fox
.
op<<l>>t<<<lam>>>>>>imi<<<><>>>zer<<<<<<<<<<<<<<<<<<>>><>m
should give llammoptimizer
.
e< <c<b<a
should give abc e
.
<<<>><><<><toast>><<>><><<>><
should give toast
.
Task 4 - FILTHE Letters
In many fonts, 6 of the uppercase English alphabet letters consist entirely of horizontal and vertical lines: E
, F
, H
, I
, L
, and T
. We'll calls these the FILTHE letters.
Take in a string of uppercase letters (A-Z) and count the number of lines in the FILTHE letters, outputting the resulting integer.
E
, F
, H
, I
, L
, and T
have 4, 3, 3, 3, 2, and 2 lines respectively.
e.g. GEOBITS
has 4 + 3 + 2 = 9 lines part of FILTHE letters (for .E..IT.
), so the output should be 9
.
ABCDEFGHIJKLMNOPQRSTUVWXYZ
should output 17
.
ABCDGJKMNOPQRSUVWXYZ
should output 0
.
FILTHYLINESINLETTERS
should output 39
.
Task 5 - Alex Recursive A.
Our moderator Alex A. has a fairly mysterious initial, "A".
Now I'm not certain, but I think the A.
stands for .A xelA
. And I'm also pretty sure that the .A
there sneakily stands for Alex A.
.
Thus to get Alex's full name we must expand out the A.
's and .A
's:
Alex A. -> Alex [A.] -> Alex [.A xelA] -> Alex .A xelA -> Alex [.A] xelA -> Alex [Alex A.] xelA -> Alex Alex A. xelA -> etc.
Have your program take in a non-negative integer and expand Alex A.
that many times, outputting the resulting string.
So
0
becomes Alex A.
,
1
becomes Alex .A xelA
,
2
becomes Alex Alex A. xelA
,
3
becomes Alex Alex .A xelA xelA
,
4
becomes Alex Alex Alex A. xelA xelA
,
5
becomes Alex Alex Alex .A xelA xelA xelA
,
and so on.
(I made this because I felt bad for inadvertently leaving Alex out of my mod tribute challenge. :P)
Task 6 - Numpad Rotation
Take in an integer from 1 to 9 inclusive (you may take it as a string). Output the 3×3 square of digits
789
456
123
rotated in increments of 90° such that the input digit appears anywhere on the top row. When 5
is input any rotation is valid output since 5
cant be rotated to the top.
e.g. when 3
is input, both
963
852
741
and
321
654
987
are valid outputs.
For input 4
, only
147
258
369
is valid output.
Task 7 - Splitting Digits Into Tens
Take in a nonempty string of decimal digits (0-9) and output a truthy value if it can be broken up into contiguous sections where all the digits in each section sum exactly to 10. If this is not possible, output a falsy value.
e.g. 19306128
can be split up like 19|3061|28
, the sections all summing to 10 (1+9, 3+0+6+1, 2+8), so a truthy value should be output.
Truthy examples (one per line):
19306128
073
730
0028115111043021333109010
2222255
Falsy examples:
6810410
9218
12341
5222225
000
Task 8 - Square Clock
Take in a consistently sized multiline string.
Output 12
if the input is
_ _
| | |
|_ _|
Output 3
if the input is
_ _
| |_|
|_ _|
Output 6
if the input is
_ _
| | |
|_|_|
Output 9
if the input is
_ _
|_| |
|_ _|
There are no other input cases.
Task 9 - Bracket Art
Take in a 4 byte string containing one of each of the left brackets (
, [
, {
, and <
in any order.
Add the corresponding right brackets so the string is 8 bytes long and has a vertical line of symmetry. e.g. [<({
becomes [<({})>]
.
Then reverse every bracket in this string. e.g. [<({})>]
becomes ]>)}{(<[
.
Output the original 8 byte bracket string with the reversed version above and below on separate lines.
So the final output for input [<({
would be
]>)}{(<[
[<({})>]
]>)}{(<[
Similarly, the output for <({[
should be
>)}][{(<
<({[]})>
>)}][{(<
The input (<<[
is invalid because the {
is missing and there is an extra <
.
Task 10 - Perimiterize
Take in a rectangular grid of text (1×1 at smallest) made of .
's that represent empty space and X
's that represent solid tiles. Cells beyond the grid bounds are considered empty. You may assume each of the 4 grid edge rows and columns will contain at least one X
.
e.g. a valid input might be:
XXX.....X.....
X..X...X.X....
XXX.....X....X
Output another rectangular grid of text where every empty cell that neighbors an X
orthogonally or diagonally, including those outside the input grid, becomes o
. So essentially a perimiter of o
's is drawn around all the portions of solid tiles. The new grid should not be any larger than it has to be.
So the output of the example above would be:
ooooo...ooo.....
oXXXoo.ooXoo....
oXooXo.oXoXo.ooo
oXXXoo.ooXoo.oXo
ooooo...ooo..ooo
Similarly, the output of input XXX..X.X
should be
oooooooooo
oXXXooXoXo
oooooooooo
and outputting
oooooooooo.
oXXXooXoXo.
oooooooooo.
would be invalid since the empty rightmost column is unnecessary.
You may use any 3 distinct printable ASCII characters in place of .
, X
, and o
.
Task 11 - Sator Square
Output the Sator Square:
SATOR
AREPO
TENET
OPERA
ROTAS
Any of the letters may be lowercase or uppercase, so
SatOR
aRePO
tenet
OPERa
RoTaS
is also valid output.
There is no input.
Task 12 - Prime Tweet
Take no input but output a 140 byte printable ASCII string that contains at least one of each of the 95 printable ASCII characters. (So 45 characters will be duplicates.)
The sum of the character codes of all 140 bytes in this string must be a Sophie Germain prime, i.e. a prime number p
such that 2p+1
is also prime. The character code for space is 32, 33 for !
, 34 for "
, and so on up to 126 for ~
. The sum could be calculated in Python as sum(map(ord, myString))
.
An example output is:
! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~STUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~d
The character code sum is the prime 12203 whose corresponding safe prime is 24407.
import
s? Let's say I write 5 functions where 2 need the same module (e.g.import Math
), is this counted twice? \$\endgroup\$