44

6

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.

7I will be impressed if anyone actually manages to solve everything in less than 140 bytes, even with CJam/Pyth – Fatalize – 2015-10-12T08:46:03.410

9I am honored to be in .a ni eb ot deronoh ma I... challenge of yours. :P – Alex A. – 2015-10-12T19:04:02.323

are tasks allowed to end with an error after the result is printed to the output? – torcado – 2015-10-12T20:57:15.887

1How should we count bytes from

`import`

s? Let's say I write 5 functions where 2 need the same module (e.g.`import Math`

), is this counted twice? – nimi – 2015-10-12T21:15:48.960@nimi It would be counted twice unfortunately. Though you can write one program for all the tasks and thus only need one import. – Calvin's Hobbies – 2015-10-12T21:22:09.223

@torcado The default is

– Martin Ender – 2015-10-13T07:21:59.917yes. (Calvin's Hobbies, you should override that explicitly if that is your intention, although that might be a bit late now... one of my solutions actually did terminate with an error before I golfed it further.)@MartinBüttner Well fine, let's stick to the default. – Calvin's Hobbies – 2015-10-13T07:53:17.117

Are submissions allowed to count flags as extra bytes, per usual policy? I ask because Pip frequently uses flags for output formatting. – DLosc – 2015-10-23T22:14:33.023

Mathematica string manipulation is

expensive... – LegionMammal978 – 2015-10-24T12:20:07.817After this bounty expires, I will offer another

400-point bountyfor the shortest combined solution in TI-BASIC in another week. – lirtosiast – 2015-10-25T05:47:18.957@ThomasKwa Do you mean task 3? You can assume there's at least 1 non

`<>`

. – Calvin's Hobbies – 2015-10-26T02:27:41.550Yes, I meant 3. – lirtosiast – 2015-10-26T02:29:28.623

In TI-BASIC, the newline character 0x3F can't actually be typed in on a default calculator. Can we still (a) take input from the

`Ans`

variable (command line-ish, can be entered using a hex editor) or (b) take input from`Input`

? In the first case a hex editor can be used to pass the string. – lirtosiast – 2015-10-26T16:52:56.990@ThomasKwa Both sound alright since TI-BASIC is a special case. – Calvin's Hobbies – 2015-10-26T18:21:09.950

As @jacobly pointed out, it's impossible to get a quote character in a string in TI-BASIC without taking input. Is it acceptable to assume that the

`Ans`

variable contains a quote character (which is what @Weregoose did)? – lirtosiast – 2015-10-27T19:14:09.500@ThomasKwa That sounds fine for TI-BASIC. – Calvin's Hobbies – 2015-10-27T19:25:44.300

In Task 12, do we need to display all of the

`tokens`

corresponding to the ASCII characters, or can we just display tokens like`sin(`

counting as s, i, n, and (? – lirtosiast – 2015-10-28T16:07:57.380@ThomasKwa Those can count. – Calvin's Hobbies – 2015-10-28T17:20:51.243

@pppery I believe that consensus covers new challenges, not existing ones. I see no need to close this challenge based on that decision – caird coinheringaahing – 2019-10-20T12:53:19.350

@cairdcoinheringaahing So, why was First code golf decathlon closed and locked if the consensus I linked to only applies to challenges that postdate it.

– pppery – 2019-10-20T13:48:36.1501

I'm voting to close this question as off-topic because it's a multi-part challenge with insufficient interaction between the parts

– pppery – 2020-01-22T01:39:15.133