Cramming The Gramming - Twelve Task Tweet
CJam, 8 9 tasks in 140 bytes
First off, here is a script you can use to sort your solutions and tell you which ones will fit into the tweet:
{\s\Se[oSo}:F;
qN/ee{W=,}${)_,_T+:T140>X*_{0:X;}*'=@11+*N+*o\~)YF_,ZFTZFoNo}/
Just paste your 12 solutions into the input, one on each line. Run it here. The first column is the task number, the second its size (in characters - you'll have to fix this yourself if that is different from the byte count), the third the cumulative size. The programs which fit into the tweet are separated from the rest with a line of ===
.
For me, the output looks like this:
1 7 7 q~$~\->
8 10 17 qDbJ%5/)3*
12 12 29 ',32>_51>'d
7 13 42 Aq{~-Ace|}/N&
2 15 57 qe!{~1e6-z}$0=~
4 19 76 q"FIHEELT"3*H<fe=:+
5 20 96 ".A"q~){" xelA"+W%}*
9 22 118 q_{_')>+)}%W%+_W%N@N3$
11 22 140 "SATOR\AREPO\TEN"_W%1>
====================================
6 25 165 9,:)s3/zq~))3mdg*{W%z}*N*
3 43 208 LLq{_'=-z({+}{'=>_)$\[{)@+\}{\(@\+}]=&}?}/\
10 45 253 0XW]_m*qN/{'.f+W%z}4*f{\~@m>fm>N*}(\{8f^.e>}/
So here are the tasks I can currently fit into the tweet.
Task 1 - Can Three Numbers Form A Triangle? - 8 7 bytes
Thanks to jimmy23013 for saving 1 byte.
q~$~\->
Test suite.
Input is expected to be CJam-style list.
This is fairly straightforward: check if the largest side is shorter than the sum of the other two. Or equivalently, check that the shortest side is longer than the difference of the other two:
q~ e# Read and eval input.
$~ e# Sort the values and dump them on the stack.
\- e# Subtract the middle value from largest.
> e# Check if the smallest value is greater than that.
Task 2 - Closest To One Million - 15 bytes
qe!{~1e6-z}$0=~
Test suite.
Simple brute force:
q e# Read input.
e! e# Get all permutations.
{ e# Sort by...
~ e# Evaluate the permutation to get its numerical value X.
1e6-z e# abs(X - 1,000,000)
}$
0= e# Pick the first element (which minimises the difference)
~ e# Evaluate it to get rid of the leading zeroes.
Task 4 - FILTHE Letters - 21 19 bytes
Thanks to jimmy23013 for saving 2 bytes.
q"FIHEELT"3*H<fe=:+
Test suite.
The idea is to create a string which contains each of the FILTHE letters once for each of their orthogonal lines. This is done via some funny string manipulation:
q e# Read the input.
"FIHEELT" e# Push this string. It first contains the 3-line letters, then the 2-line
e# letters, where we include 'E' twice to make it count for 4.
3* e# Repeat 3 times: "FIHEELTFIHEELTFIHEELT"
H< e# Truncate to 17 characters: "FIHEELTFIHEELTFIH". This is chosen such that
e# it discards the third repetition of the 2-line letters.
fe= e# For each character in the input, count its occurrences in this new string.
:+ e# Sum them all up.
Task 5 - Alex Recursive A. - 27 20 bytes
".A"q~){" xelA"+W%}*
Test suite.
Implemeting the substition of A.
and .A
directly is way too expensive. Instead, we notice that we only have to handle one case, if we reverse the string each time. Furthermore, prepending Alex
(and a space) each time is equivalent to expanding the initial. We can save another byte by appending the reverse before reversing the string:
".A" e# Start with ".A" (the -1st iteration if you like).
q~) e# Read input, eval, increment (so the following block is run at least once.)
{ e# Repeat this block that many times...
" xelA"+ e# Append " xelA".
W% e# Reverse the string.
}*
Task 7 - Splitting Digits Into Tens - 18 16 13 bytes
Aq{~-Ace|}/N&
Test suite. (With brackets around each output.)
Not exactly user friendly: the truthy value is a single newline, the falsy value is the empty string.
The basic idea is simple: add the digits to a running total which we reset whenever it hits exactly 10. The total must be zero at the end of the input. For a start it turns out to be shorter to the total at 10 and subtract the digits, resetting the total whenever we hit 0. However, we need to make sure that we don't return something truthy when the input is all zeroes. The shortest way I found to do that was to reset the total to the character with code point 10 (the linefeed), and then check at the end that we actually have that character on the stack, and not the number 10. This works, because both the integer zero and the character zero (the null byte) are falsy:
A e# Push a 10, the initial running total.
q{ e# For each character in the input...
~- e# Evaluate the character to get the digit and subtract it from the total.
Ac e# Push a linefeed character.
e| e# Logical OR of the running total and the linefeed character (using
e# short-circuiting).
}/
N& e# Take the set intersection with the string containing a linefeed character.
e# If the total is still a number of any character other than the linefeed,
e# this will yield an empty string. Otherwise, the string will remain unchanged
e# and the linefeed will be printed.
Task 8 - Square Clock - 10 bytes
qDbJ%5/)3*
Test suite.
This is just some pretty random modulo magic on the character codes which happens to hash to the correct values. I'm fairly convinced that something shorter is possible, but it's the shortest I found (programmatically) for this kind of structure:
q e# Read the input.
Db e# Treat the character codes of the string as digits in base 13. This maps the
e# four inputs to the values: 2023940117708546863
e# 2023940113755405840
e# 2023940781838850791
e# 2023940113755390292
J% e# Take the result modulo 19. This gives [2, 5, 12, 18], respectively.
5/ e# Divide by 5 (rounding down). [0, 1, 2, 3], respectively.
) e# Increment. [1, 2, 3, 4], respectively.
3* e# Multiply by 3. [3, 6, 9, 12], respectively.
Task 9 - Bracket Art - 23 22 bytes
Thanks to Sp3000 for saving 1 byte.
q_{_')>+)}%W%+_W%N@N3$
Test suite.
Fairly straightforward. The mapping between the left and right brackets is done by adding 2 (or 1 for parentheses):
q_ e# Read input and duplicate.
{ e# Map this block onto each character...
_')> e# Duplicate and check if it's not a parenthesis.
+ e# Add the result, leaving parentheses unchanged and incrementing the
e# other bracket types.
) e# Increment again.
}%
W%+ e# Reverse and add to the original, giving the middle line.
_W% e# Duplicate and reverse, giving the first line.
N@ e# Push a linefeed, pull up the middle line.
N3$ e# Push another linefeed, copy the first line.
Task 11 - Sator Square - 22 bytes
"SATOR
AREPO
TEN"_W%1>
Test it here.
Probably the most boring solution of all. It pushes the first half of the string and then reverses it:
"SATOR
AREPO
TEN" e# Push everything up to the centre of the square.
_W% e# Duplicate and reverse.
1> e# Discard the "N", because we don't want that twice.
Task 12 - Prime Tweet - 13 12 bytes
',32>_51>'d
Test it here. (With diagnostic output for the result.)
After '
there's the unprintable <DEL>
(0x7F), which SE strips out. For copy-pasting, use this version instead:
'~),32>_51>'d
The printed string is
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~STUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~d
That is, it contains one run of all characters, followed by another run from S
to ~
, followed by a single d
. The sum of the character codes is 12203. I found this via a bit of trial and error.
'~),32> e# Push a string with all printable characters.
_51> e# Duplicate this and discard the first 51 of them.
'd e# Push a "d".
Pyth, 9 tasks in 138 bytes
This took quite a while.
I think 9 tasks is the limit for Pyth. Including the next shortest program (Sator Square) results in 160 bytes. Golfing 20 bytes is quite unlikely. There are 2 or 3 tasks which are a little bit ugly and maybe can be shortened, but overall I'm quite pleased with the solutions.
Task 1 - Can Three Numbers Form A Triangle?, 8 bytes
>FsMc2SQ
Try it online: Regular Input or Test Suite
Task 2 - Closest To One Million, 14 bytes
ho.a-^T6NsM.pz
Try it online: Regular Input or Test Suite
Task 4 - FILTHE Letters, 20 bytes
s*Vtsmmdd5/Lz"TLIHFE
Try it online: Regular Input or Test Suite
Task 5 - Alex Recursive A., 16 bytes
u+"Alex "_GhQ".A
Try it online: Regular Input or Test Suite
Task 6 - Numpad Rotation, 20 bytes
jeo}zhN.uC_N3_c3jkS9
Try it online: Regular Input or Test Suite
Task 7 - Splitting Digits Into Tens, 15 bytes
qTu+WnGTvHG-zZZ
Try it online: Regular Input or Test Suite
Task 8 - Square Clock, 12 bytes
*3%%Cz1978 5
Try it online: Regular Input or Test Suite
Task 9 - Bracket Art, 20 bytes
V3_WtN+z_Xz"[<({})>]
Try it online: Regular Input or Test Suite
Task 12 - Prime Tweet, 13 bytes
++*d44srd\\&
Try it online: Regular Input
Pyth, 9 tasks in 136 bytes
Task 1: 7 bytes
<-F_SQ0
Demonstration
Sort in descending order (_SQ
), fold subtraction over them (a-b-c
), check if the result is negative.
Task 2: 14 bytes
sho.a-sN^T6.pz
Demonstration
Form all string permutations (.pz
), sort them (o
) based on the absolute value of the difference (.a-
) between the number (sN
) and one million (^T6
).
Take the first such string (h
), and convert it to a num. (s
).
Task 4: 19 bytes
s/L+\EPP*3"EFHILT"z
Demonstration
Replicate "EFHILT"
three times (*3
), remove the trailing LT
(PP
), and add an E
(+\E
). Map each letter in the input to its appearance count in that string. (/L ... z
). Sum. (s
).
Task 5: 16 bytes
u+"Alex "_GhQ".A
Demonstration
Starting with "A."
, reverse and add an "Alex "
to the start, input + 1 times.
Task 7: 13 bytes
}Y-RTsMM./sMz
Convert the input string into a list of 1-digit numbers (sMz
). Form all partitions (./
). Sum each element of each partition (sMM
). Remove all 10s from each sublist (-RT
). Check if this emptied out any of the sublists by checking if the empty list is in the overall list (}Y
).
Task 8: 11 bytes
*3h%%CQC\Ç4
Demonstration
Modulo magic. Convert to number (CQ
), take it mod 199 (C\Ç
= 199), and take that mod 4. Then add 1, and multiply by 3.
Task 9: 21 bytes
J+Xz"<{[()]}>")_zJ_JJ
Demonstration
First, we generate the first line, which consists of the input translated to the mirror characters (Xz"<{[()]}>")
), followed by the reversed input (+ ... _z
), and save it to J
. Then print that line, its reverse, and that line again (J_JJ
).
Task 11: 22 bytes
+J"SATOR
AREPO
TEN"t_J
Demonstration
Just print a string and its reversal, but don't duplicate the center N
.
Task 12: 13 bytes
++G*19\3srd\
Demonstration
There is an invisble DEL
(7F
) character at the end of the code.
This prints
abcdefghijklmnopqrstuvwxyz3333333333333333333 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
which has character sum 11321
. It consists of G
, the alphabet, 19 3
s, and all of the printable ASCII characters.