title: Make me some sushi

text:
# Question
Title: Make me some sushi
It's lunch time, I am hungry and I came to your Sushi Bar. You are the Sushi Chef and you have to produce a full program or function to make me some sushi!

Credits: Wikipedia

*Disclaimer: The image is for illustration purposes only and do not necessarily represent the exact product.*

Although you have limited ingredients (due to a truck drivers strike) it will be fine for me.

The ingredients you have (in plenty amount) are:

* Nori seaweed (made with: `\/_¯|`)
* Raw Tuna (`T`)
* Raw Salmon (`S`)
* Raw Avocado (`A`)
* Sushi Rice (`o`)

With these ingredients you are able to make some nice makis for your clients.

Your minimum order is $1 for 2 makis, you only make makis in couples and only accept integer numbers as payment. You accept orders up to $50 per person (total input) because you are alone and you must satisfy all your clients.

You will need to get the client's orders from standard input in any reasonable format, for example: `[1,T],[2,S],[3,A]` which means that you have to output:

* Two Tuna Makis
* Four Salmon Makis
* Six Avocado Makis

One maki is exactly made like this:

```
   _____
  /ooooo\
 |ooTTToo|
 |\ooooo/|
 | ¯¯¯¯¯ |
  \_____/

```

And since you are a fine Sushi Chef, you always arrange the makis with the pieces of any given type in a square shape or at most in a rectangular shape (as close as possible to a square) with no gaps. The overall shape is also square or rectangular, as close as possible to a square given the above restriction, with no gaps.

**Example input/outputs:**

```
Input: [1,T],[2,S],[3,A]

Valid Output:
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooTTToo||ooTTToo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooSSSoo||ooSSSoo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooSSSoo||ooSSSoo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/

Valid Output:
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo||ooSSSoo||ooSSSoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo||ooSSSoo||ooSSSoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo||ooTTToo||ooTTToo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/

Not Valid Output:
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooTTToo||ooAAAoo||ooSSSoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooSSSoo||ooAAAoo||ooTTToo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooSSSoo||ooSSSoo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/

Not Valid Output:
  _____    _____    _____    _____    _____    _____    _____    _____    _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooTTToo||ooTTToo||ooSSSoo||ooSSSoo||ooSSSoo||ooSSSoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/

Not Valid Output:
  _____    _____    _____    _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooTTToo||ooTTToo||ooSSSoo||ooSSSoo||ooSSSoo||ooSSSoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/  \_____/

Input: [1,S]

Valid Output:
  _____    _____
 /ooooo\  /ooooo\
|ooSSSoo||ooSSSoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/

Valid Output:
  _____
 /ooooo\
|ooSSSoo|
|\ooooo/|
| ¯¯¯¯¯ |
 \_____/
  _____
 /ooooo\
|ooSSSoo|
|\ooooo/|
| ¯¯¯¯¯ |
 \_____/

Input: [1,A],[1,T],[1,S]

Valid Output:
  _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\
|ooAAAoo||ooTTToo||ooSSSoo|
|\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/
  _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\
|ooAAAoo||ooTTToo||ooSSSoo|
|\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/

Valid Output:
  _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\
|ooTTToo||ooTTToo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/
  _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\
|ooSSSoo||ooSSSoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/

Input: [1,T],[1,A],[2,S]

Valid Output:
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooTTToo||ooTTToo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooSSSoo||ooSSSoo||ooSSSoo||ooSSSoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/

Valid Output:
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooTTToo||ooTTToo||ooSSSoo||ooSSSoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo||ooSSSoo||ooSSSoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/

Valid Output:
  _____    _____
 /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooSSSoo||ooSSSoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooSSSoo||ooSSSoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooTTToo||ooTTToo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/

Input: [1,T],[1,S],[7,A]

Valid Output:
  _____    _____    _____    _____    _____    _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooSSSoo||ooSSSoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____    _____    _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooTTToo||ooTTToo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/

 Valid Output:
  _____    _____
 /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooSSSoo||ooSSSoo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/
  _____    _____
 /ooooo\  /ooooo\
|ooTTToo||ooTTToo|
|\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/

```

**Rules:**

# Answer
> 2 votes
# Python 3, ~~314~~ 313 bytes

```
l=["  _____  "," /ooooo\ ","|oo%s%s%soo|","|\ooooo/|","| ¯¯¯¯¯ |"," \_____/ "];T=('T',)*3;S=('S',)*3;A=('A',)*3;i=eval('['+input()+']');x=sum(map(lambda x:x[0],i));m=[]
for f in i:m+=[f[1]]*f[0]
for p in 1,0:
    for j in l:
        for k in range(x):print((j%m[k]if '%s' in j else j),end='')
        print()

```

My attempt at this challenge. It's hard!

### Sample Output:

```
[1,T],[1,S],[7,A]
  _____    _____    _____    _____    _____    _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooTTToo||ooSSSoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/
  _____    _____    _____    _____    _____    _____    _____    _____    _____
 /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\  /ooooo\
|ooTTToo||ooSSSoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo||ooAAAoo|
|\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/||\ooooo/|
| ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ || ¯¯¯¯¯ |
 \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/  \_____/

```

---
Tags: code-golf, ascii-art
---


# Question
Title: Missing Integer Sequence Detection -- Filesystem
The challenge is to detect missing integer sequences of files or directories. You have a directory filled with files/directories that are named as integers.

The files/directories are generated from multiple threads yet the job did not complete - there are therefore gaps in the sequence.

The input is two integers a start and an end, and your task is detect the starting integer of the next missing sequences. You may presume that all files and directories in the directory where run have only integer named files or directories.

Acceptable answer forms: functions, code snippets - they must run on the command line.
Acceptable start/end input: included on the command line, **env variables/argv are okay**, parameters to functions, **user input is okay**.
**Shortest code wins.**

**Update -- Although I managed to squeeze out this one, there were many interesting answers. The idea in apricotboy's Bash answer was used in part to help me design my 35 Byte Bash answer. Best of luck on the next one.**

```
E.g. Presume files 1,2,3,4,7,8,9,10,18 are present, start is 1, end is 20:

The output should be:
5
11
19

```

# Answer
# Python 2, 101 bytes

**2 bytes thanks to @xnor.**

```
import os
t=-1
for n in range(input(),input()+1):
 if~-os.path.isfile(str(n)):
  if~t+n:print n
  t=n

```
> 5 votes

# Answer
# Ruby, ~~74~~ ~~60~~ 45 bytes

Input is in command line, run it like `ruby f.rb 0 20`. Only works in current directory.

*-1 byte from unpacking the `ARGV` into variables, and -13 bytes from replacing the `select` and `grep` with a set subtraction.*

V3: *-5 bytes from using a substitution for `Dir.glob` in an old Ruby answer to another filesystems challenge, as suggested by @PatrickOscity. -10 from remembering some quirks in Ruby's `String#next` function.*

```
a,b=$*
f=[*a..b]-Dir[?*]
puts f-f.map(&:next)

```
> 4 votes

# Answer
# Dyalog APL, ~~25~~ 24 or 36 bytes

Prompts for lower bound, then upper bound.

It seems from comments to other answers that the OP wanted as short sequences as possible.

```
{⍵/⍨~⍵∊⍨⍵-1}((⍳⎕)~⍳⎕-1)~⍎¨⎕SH'dir/b'

```

`{`
`⍵/⍨` those where it is
`~` not true
`⍵∊⍨` that the set contains
`⍵-1` their predecessor
`}` of
`(`
`(⍳⎕)` of the integers until *n*
`~` except
`⍳⎕-1` integers until *n*-1
`)~` except
`⍎¨` the evaluation of each of
`⎕SH'dir/b'` the bare list of names in the current directory

---

Old answer which returns length-1 sequences:

```
(⍕¨(⍳⎕)~⍳⎕-1)~⎕SH'dir/b'

```

`(`
string representation
`¨` of each
`(⍳⎕)` of the integers until *n*
`~` except
`⍳⎕-1` integers until *n*-1
`)~` except
`⎕SH'dir/b'` the bare list of files in current directory

Only works on Windows. A cross platform solution:

```
(⍕¨(⍳⎕)~⍳⎕-1)~0⎕NINFO⍠1⊢'*'

```

`0` just the filename(s)
`⎕NINFO` of the Native file(s) INFOrmation
`⍠1` using wildcards
`⊢'*'` on all files
> 4 votes

# Answer
# Perl 6, 47 bytes

```
{my \c;.say if .IO.e??(c=0)!!!c++ for $^a..$^b}

```

Explanation:

```
{my \c;.say if .IO.e??(c=0)!!!c++ for $^a..$^b}
{                                               } # A function. Arguments: $^a and $^b (implicitly)
 my \c;                                           # A variable without prefix (\ is needed only here)
                                  for $^a..$^b    # For each number between $^a and $^b
       .say if                                    # Print the number if the result is truthy:
               .IO.e??(c=0)!!!c++                 # If the file exists, reset the sequence (don't print this one), otherwise, return the `!(c++)` result (is it the first time we're incrementing)

```

Tried to use flipflops. Didn't manage to :P.
> 4 votes

# Answer
# PHP, 64 bytes

```
<?=implode("\n",array_diff(range($argv[1],$argv[2]),glob("*")));

```

Run like this:

```
php -f golf.php 1 20

```

Note:

* Only does the current directory.
* No trailing newline on the output.
* This requires the `<?=` to be allowed in php.ini. Which I think is default but I'm not sure.

# Bash, 31 bytes

```
a(){(seq $@;ls)|sort|uniq -u;}

```

Run as `a 1 20`. Again, only does the current dir.

Can I submit two? Hope so. This is my first post to Code Golf so I'm not too sure of the etiquette. Hope I'm counting my bytes correctly, too.
> 1 votes

# Answer
I see now this is an old question, but still, I like it...

# PowerShell, 70 bytes

```
for($m,$n=$args;$m-le$n;$m++){$w=$a;$a=Test-Path $m;if(!$a-and$w){$m}}

```

Run as a script from the command line, eg .\misso.ps1 1 20.
> 1 votes

# Answer
## PowerShell v4+, 62 bytes

```
param($x,$y)$x..$y|?{$_-notin($a=(ls ".\").Name)-and$_-1-in$a}

```

Save as a script in the desired directory and call it locally (see example below). Takes input `$x` and `$y` and constructs a range `..`, then pipes that to a `Where-Object` (the `|?{...}`) which is basically a filter. Here we're only selecting items where the current element `$_` is `-notin` the `.Name` collection of the current directory, *but* the previous element is `-in` that collection (i.e., only the start of a missing range).

The `ls` is an alias for `Get-ChildItem` and is basically what you'd expect. Requires v4 for the encapsulation-select of `.Name`, otherwise you'd need `$a=ls ".\"|select Name`.

### Example

```
PS C:\Tools\Scripts\golfing\misd> ls .\

    Directory: C:\Tools\Scripts\golfing\misd

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         7/26/2016   7:48 AM          8 1
-a---         7/26/2016   7:48 AM         10 10
-a---         7/26/2016   7:54 AM          0 18
-a---         7/26/2016   7:48 AM          8 2
-a---         7/26/2016   7:48 AM          8 3
-a---         7/26/2016   7:48 AM          8 4
-a---         7/26/2016   7:48 AM         10 7
-a---         7/26/2016   7:48 AM          8 8
-a---         7/26/2016   7:48 AM          8 9
-a---         7/26/2016   8:18 AM        365 misd.ps1

PS C:\Tools\Scripts\golfing\misd> .\misd.ps1 1 20
5
11
19

```
> 0 votes

# Answer
# Groovy, 53 bytes

```
{f,s,e->(s..e)-f.listFiles().collect{it.name as int}}

```

I had an explanation and screenshots, but I didn't post that version and left the page... Either that or I posted the answer to a random S.O. thread about the "best way to stat a directory in Groovy".
> 0 votes

---
Tags: code-golf, sequence, subsequence, file-system
---


title: The hourglass challenge

text:
# Question
Title: The hourglass challenge
# The Hourglass

This hourglass has 60 "sands of time", and it completely fills each chamber. The clock is 19 characters wide and 13 characters in height. Each chamber has 5 rows of sand and there is a row in the centre that can hold 1 sand. The top row can hold 17 sands, the next one 15 and so on (see below). Sands fall in to the bottom chamber at the rate of one sand per second.

```
       START                     3 SECONDS LATER               38 SECONDS LATER

███████████████████            ███████████████████            ███████████████████
█.................█   17       █..............   █   14       █                 █    0
██...............██   15       ██...............██   15       ██               ██    0
███.............███   13       ███.............███   13       ███.......      ███    7
█████.........█████   09       █████.........█████   09       █████.........█████   09
███████.....███████   05       ███████.....███████   05       ███████.....███████   05
█████████.█████████   01       █████████.█████████   01       █████████.█████████   01
███████     ███████            ███████  .  ███████            ███████  .  ███████
█████         █████            █████    .    █████            █████    .    █████
███             ███            ███      .      ███            ███....         ███
██               ██            ██               ██            ██...............██
█                 █            █                 █            █.................█
███████████████████            ███████████████████            ███████████████████

```

# The Challenge

Display the hourglass (no numbers or headings are required) after a certain period of time (0 ≤ t ≤ 60).

# Coding Rules

1. The hourglass should look exactly as shown here. You may replace the  character and/or the **`.`** character with whatever you like to fit your language (Unicode, ASCII compatibility issues).
2. The input should be a number such as 45 or 7. Display the clock after these many seconds.
3. The output can either be displayed or saved to a file. No extra text or labels as shown above are required - just the hourglass is all we need.
4. If the user enters t \> 60, you don't have to handle the error.

# Points

1. Shortest code wins.

# Answer
# JavaScript (*ES6*), 203  ~~208 233 270 256~~ characters

**Edit** Revised using a loop instead of a sequence of calls.

**Edit** Added top and bottom row that were missing.

A function returning the output. Run the snippet in Firefox to test.

```
f=w=>[h='█'[R='repeat'](19),...[17,15,13,9,5,1,5,9,13,15,17].map((d,i)=>(t=i>5?-v:v,v-=i<5?d:1-d,e=' '[R](d/2),b='█'[R](10-d/2),b+('.'[R](t<d&&d-t)+e+' .'[i>4&w>i-6&t>=d|0]+e).slice(0,d)+b),v=w),h].join`
`

// Less golfed
F=
w=>[h='█'.repeat(19),
    ... [17, 15, 13, 9, 5, 1, 5, 9, 13, 15, 17].map(
     (d,i) => (
       t = i>5 ? -v : v,
       v -= i<5 ? d : 1-d,
       e = ' '.repeat(d / 2),
       b = '█'.repeat(10 - d / 2),
       b +
        ('.'.repeat(t < d && d - t)
         + e + ' .'[i > 4 & w > i-6 & t >= d | 0]
         + e).slice(0,d)
       + b
     ), v = w
    ),
    h].join('\n')

// TEST

O.innerHTML=f(+I.value)

function tick(d) {
  var i=+I.value+d
  I.value=i
  O.innerHTML=f(i)
}

var int=0;

function auto()
{
  function go()
  {
    var t = I.value;
    O.innerHTML=f(++t)
    if (t>70)t=0;
    I.value = t;
  }
  if (A.checked && !int)
  {
    int = setInterval(go, 200);
  }
  else if (!A.checked && int)
  {
    clearInterval(int);
    int = 0;
  }
}
```

```
input[type=text] { width: 3em }
```

```
<button onclick='tick(-1)'>-</button>
<input type=text id=I value=0 onchange='tick(0)' >
<button onclick='tick(1)'>+</button>
<input type=checkbox id=A onclick='auto()'>Fly time
<pre id=O><pre>
```
> 27 votes

# Answer
## Python 2, 200

```
t=input()+1
s=' '*t+'.'*60+' '*70
n=0
d=sum((1<t<56,2<t<48,3<t<36,4<t<22))
for c in'ctrplhdhlprtc':i=ord(c)-99;print[s[n+i:n:-1],[s[180-n-i+d:][:i],'.'][5+d*3>i>0]][n>59].center(i).center(19,'#');n+=i

```

xnor has made a **197** byte version in the chat.

I would post an explanation, but I've lost track of how it actually works...

Also, here's an animated version with curses:

```
from curses import*
w=initscr()

for t in range(1,61):
    s=' '*t+'.'*60+' '*70
    n=0
    d=sum((1<t<56,2<t<48,3<t<36,4<t<22))
    for i in 0,17,15,13,9,5,1,5,9,13,15,17,0:w.addstr([s[n+i:n:-1],[s[180-n-i+d:][:i],'.'][5+d*3>i>0]][n>59].center(i).center(19,'#')+"\n");n+=i
    w.refresh()
    w.clear()
    napms(999)

endwin()

```
> 19 votes

# Answer
# Python 2.7, ~~362~~ ~~356~~ 347

```
e,c,x,a,b,n=' .#ab\n';R,r,s,l,T,m=range,str.replace,'',19,[1,2,3,5,7,9],-1
for t in[T,T[:m][::m]]:s+=''.join([n+x*y+c*(l-y*2)+x*y for y in t]);c=b
s=list(s)
for i in R(130,220,20):s[i]=a
for _ in R(input()):s[s.index('.')]=e;i=s.index(a)if a in s else 219-s[::m].index(b);s[i]='.'
for l in(x*l+r(r(''.join(s),a,e),b,e)+n+x*l).split(n):print l[::m]

```

Output at 38 seconds :

```
###################
#                 #
##               ##
###.......      ###
#####.........#####
#######.....#######
#########.#########
#######  .  #######
#####    .    #####
###...   .      ###
##...............##
#.................#
###################

```
> 13 votes

# Answer
# C 544

Here's what I have so far for a C solution.

```
#include <stdio.h>
int main(int z,char **a){int r,i,y=i=0,v,d,t,m,s=atoi(a[1]),n[13]={0,43,28,15,6,1,0,1,5,13,25,39,0};char H[13][20];while(y<13){int x,b=x=i=0;v=y-6;t=3+abs(v);m=2*abs(v);d=t<m?t:m;d=9-d;if(d==0)d=10;while (b<d){H[y][b]='#';H[y][18-b]='#';b++;}while(x<19-2*b){if(x<=s-n[y])H[y][x+b]=v>0?' ':'.';else H[y][x+b]=v>0?'.':' ';x++;}if(s>58)r=0;else if(s==58)r=1;else if(s==57)r=2;else if(s==56)r=3;else if(s>38)r=4;else if(s>24)r=3;else if(s>12)r=2;else if(s>4)r=1;while(i<r){H[7+i][9]='.';i++;}H[y][19]='\n';y++;}fputs(H,stdout);}

```

Compiled with the following command:

```
gcc -w -o hourglass hourglass.c  // I realize I should have cast H as a char *, but since it works this way, I just decided to suppress the error from the compiler instead to save space.

```

Admittedly, this language has a lot of bulk- that include statement was a bit of a handicap coming right out of the blocks, but I really was just looking for an excuse to practice using C.

I hope you like my solution, and let me know if you see ways to improve.
> 3 votes

# Answer
# Matlab, 252 bytes

The idea is constructing a matrix that looks like this:

```
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0  17  16  15  14  13  12  11  10   9   8   7   6   5   4   3   2   1   0
0   0  32  31  30  29  28  27  26  25  24  23  22  21  20  19  18   0   0
0   0   0  45  44  43  42  41  40  39  38  37  36  35  34  33   0   0   0
0   0   0   0   0  54  53  52  51  50  49  48  47  46   0   0   0   0   0
0   0   0   0   0   0   0  59  58  57  56  55   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0  60   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0 116 117  61 118 119   0   0   0   0   0   0   0
0   0   0   0   0 108 109 110 111  62 112 113 114 115   0   0   0   0   0
0   0   0  96  97  98  99 100 101  63 102 103 104 105 106 107   0   0   0
0   0  82  83  84  85  86  87  88  64  89  90  91  92  93  94  95   0   0
0  66  67  68  69  70  71  72  73  65  74  75  76  77  78  79  80  81   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0

```

From there it is easy to fill the entries with the strings dependent on `n` (filling all entries that are greater than `n` and smaller than `n+60` with dots)

```
function c=f(n);
b=zeros(13,19);
z=[0,17,32,45,54,59];
y=-2:3;
for k=2:6;
    d=k+sum(k>4:5);
    b(k,d:20-d)=z(k):-1:z(k-1)+1;
    b(14-k,d:19-d)=68+(z(k-1):z(k)-2)-k;
end;
b(8:12,11:19)=b(8:12,10:18);
b(7:12,10)=60:65;c=[ones(13,19)*32,''];
c(~b)='¶';c(n<b)=46;c(b>n+60)=32

```

For `n=38` we get this output:

```
¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
¶                 ¶
¶¶               ¶¶
¶¶¶.......      ¶¶¶
¶¶¶¶¶.........¶¶¶¶¶
¶¶¶¶¶¶¶.....¶¶¶¶¶¶¶
¶¶¶¶¶¶¶¶¶.¶¶¶¶¶¶¶¶¶
¶¶¶¶¶¶¶  .  ¶¶¶¶¶¶¶
¶¶¶¶¶    .    ¶¶¶¶¶
¶¶¶...   .      ¶¶¶
¶¶...............¶¶
¶.................¶
¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶

```
> 3 votes

# Answer
# Java, 712

Input is taken from the command line. Handles both negative values for the time as well as larger than required.

```
enum H{;public static void main(String[]r){int x=0,y=0,z=0,l,t=Integer.parseInt(r[0]);String b="",d="█",e=" ",f=".",n="\n",j,k,a="███████████████████"+n;int[]w={17,15,13,9,5},v;int[][]h=new int[10][];for(;x<5;){l=w[x];v=(h[x++]=new int[l--]);l/=2;v[l]=++z;for(y=0;y++<l;){v[l-y]=++z;v[l+y]=++z;}}for(z=0;x>0;){l=w[--x];v=(h[9-x]=new int[l--]);v[l/2]=++z;}for(;x<5;){l=(w[x]-1)/2;v=h[9-x++];for(y=0;y++<l;){v[l-y]=++z;v[l+y]=++z;}}p(a);for(x=0;x<5;x++){l=w[x];j=b;for(y=0;y++*2<19-l;)j+=d;k=b;for(y=0;y<l;)k+=t<h[x][y++]?f:e;p(j+k+j+n);}j="█████████";p(j+f+j+n);for(;x>0;){l=w[--x];j=b;for(y=0;y++*2<19-l;)j+=d;k=b;for(y=0;y<l;)k+=t<h[9-x][y++]?e:f;p(j+k+j+n);}p(a);}static void p(String s){System.out.print(s);}}

```

output:

```
time: 0
███████████████████
█.................█
██...............██
███.............███
█████.........█████
███████.....███████
█████████.█████████
███████     ███████
█████         █████
███             ███
██               ██
█                 █
███████████████████

time: 1
███████████████████
█........ ........█
██...............██
███.............███
█████.........█████
███████.....███████
█████████.█████████
███████  .  ███████
█████         █████
███             ███
██               ██
█                 █
███████████████████

time: 9
███████████████████
█....         ....█
██...............██
███.............███
█████.........█████
███████.....███████
█████████.█████████
███████  .  ███████
█████    .    █████
███      .      ███
██       .       ██
█      .....      █
███████████████████

time: 41
███████████████████
█                 █
██               ██
███..         ..███
█████.........█████
███████.....███████
█████████.█████████
███████  .  ███████
█████    .    █████
███   .......   ███
██...............██
█.................█
███████████████████

```

It fills the sand from the center expanding outwards. I can probably golf it more if I get lazy with how it fills the bottom half and empties the top half. But for now I quite like it.
> 2 votes

# Answer
**Haskell 512 Bytes**

```
h=[17,15,13,9,5,1];b=drop 1$reverse h;n#s=[1..n]>>[s];s='.';n =' ';c q=(q#n)++(60-q)#s;f q|q<=5=q#s|3>2=g#s where{g=foldl i 5 (scanl (+) 0 h);i x y=if q>x+y then x-1 else x};e q=j#s++(59-length(k q)-(j))#n where{j=q-length(f q)};l q=c q++k q++(reverse$e q);p _ []=[];p x y=reverse(z++take q x++z):p (drop (head y) x) (tail y)where{q=head y;z=replicate(div (19-q) 2) '|'};k q= (concat.map(\x -> z x ++ "." ++ z x).take (length.f$q)$b)where{z x=(div x 2)#n};m n=mapM_ putStrLn $ t ++ p (l n) (h++b) ++ t;t=[19#'|']

```

Input `m 55`

Output

```
|||||||||||||||||||
|                 |
||               ||
|||             |||
|||||         |||||
|||||||.... |||||||
|||||||||.|||||||||
|||||||  .  |||||||
|||||.........|||||
|||.............|||
||...............||
|.................|
|||||||||||||||||||

```

Input `m 48` Output

```
    |||||||||||||||||||
    |                 |
    ||               ||
    |||             |||
    |||||......   |||||
    |||||||.....|||||||
    |||||||||.|||||||||
    |||||||  .  |||||||
    |||||..       |||||
    |||.............|||
    ||...............||
    |.................|
    |||||||||||||||||||

```
> 2 votes

# Answer
# Ruby: ~~196~~ ~~190~~ ~~186~~ ~~185~~ 184 characters

```
u=[0,17,15,13,9,5].map{|i|(?.*i).center 19,?#}*$/
(?1..$*[0]).map{u[?.]=' '}
l=u.reverse
5.times{|i|l[p=i*20+9]==?.&&l[' ']&&(l[p]=?|)&&l[' ']=?.}
puts u,?#*9+?.+?#*9,l.tr('. | ',' .')

```

CW because not conforms exactly to the posted samples as this consumes sand starting from the left. Mostly just a demonstration of `String.[]=` method.

Sample run:

```
bash-4.3$ ruby hg.rb 38
###################
#                 #
##               ##
###      .......###
#####.........#####
#######.....#######
#########.#########
#######  .  #######
#####    .    #####
###      .   ...###
##...............##
#.................#
###################

```

# Ruby: 215 characters

This is generates the exact required output:

```
u=[0,17,15,13,9,5].map{|i|(?.*i).center 19,?#}*$/
(?1..$*[0]).map{u[?.]=' '}
l=u.reverse
5.times{|i|l[p=i*20+9]==?.&&l[' ']&&(l[p]=?|)&&l[' ']=?.}
puts ([u,?#*9+?.+?#*9,l.tr('. | ',' .')]*$/).split($/).map &:reverse

```

Sample run:

```
bash-4.3$ ruby hg.rb 38
###################
#                 #
##               ##
###.......      ###
#####.........#####
#######.....#######
#########.#########
#######  .  #######
#####    .    #####
###...   .      ###
##...............##
#.................#
###################

```
> 1 votes

# Answer
# C#, 382 ~~410~~

it might still be possible to reduce it by a few bytes...

```
class Program{static void Main(){int u=60-22,d=u,i,j,k,l,m;var c=new char[260];var r=new int[]{0,17,15,13,9,5,1,5,9,13,15,17,0,54,45,32,17,0};for(i=0;i<13;){m=0;l=(19-r[i])/2-1;for(j=19;j>=0;){k=i*20+j--;var b=j>=l&&j<r[i]+l;if(i>6&b)c[k-r[i]+m++ +m]=r[i+6]<d&&d-->0||j==8&r[i+6]>d&&d-->0?'.':' ';else c[k]=i<7&b?u-->1?' ':'.':'█';}c[++i*20-1]='\n';}System.Console.WriteLine(c);}}

```

Fiddler - 38sec
> 0 votes

---
Tags: code-golf, ascii-art
---


# Question
Title: Cramming The Gramming - Twelve Task Tweet
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.

<sup>(I made this because I felt bad for inadvertently leaving Alex out of my mod tribute challenge. :P)</sup>

---

### 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.

# Answer
> 10 votes
# 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.

# Answer
> 27 votes
## 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".

```

# Answer
> 19 votes
# 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

# Answer
> 8 votes
# TI-BASIC, 4 Tasks in 110 bytes

# Task 1 in 7 bytes

```
:2max(Ans)<sum(Ans

```

Input is a list in `Ans`.

# Task 4 in 35 bytes

```
:sum(int(2seq(inString("TLIHFE",sub(Ans,I,1))^.4,I,1,length(Ans

```

Input is a string in `Ans`.

# Task 8 in 29 bytes

```
:18fPart(sum(seq(I(sub(Ans,I,1)=" ")/6,I,1,15

```

Input is a string in `Ans`.

# Task 11 in 39 bytes

```
:Disp "SATOR
:Disp "AREPO
:Disp "TENET
:Disp "OPERA
:Disp "ROTAS

```

---

Bonus round! Here are all the other tasks just for fun.

# Task 2 in 92 110 bytes

```
:seq(expr(sub(Ans,I,1)),I,1,7→L₁
:SortA(L₁
:min(7,1+sum(not(L₁
:{L₁(1)+sum(seq(L₁(I))₁₀^(I-8),I,2,7)),L₁(Ans)+sum(seq((I>Ans)L₁(I)₁₀^(1-I),I,2,7
:ᴇ6Ans(1+(0>min(ΔList(abs(1-Ans

```

Prompts for a list of digits Input is a string in `Ans`.

# Task 3 in 119 bytes

```
:Input Str1
:"  →Str2
:For(I,1,length(Str1
:sub(Str1,I,1→Str3
:inString("<>",Ans
:If Ans:Then
:max(0,min(L,C+2Ans-3→C
:Else
:C+1→C
:L+1→L
:sub(Str2,1,C)+Str3+sub(Str2,C+1,L-C+1→Str2
:End
:End
:sub(Str2,2,L

```

Prompts for a string. Assumes C and L are either undefined or 0.

# Task 5 in 63 bytes

```
:Ans/2→C
:sub("A.A",1+2fPart(C),2
:For(I,0,C
 :"Alex "+Ans
 :If I≠C
  :Ans+" xelA
:End
:Ans

```

Input is a number in `Ans`.

# Task 6 in 66 bytes

```
:^((Ans<7)(Ans-3(Ans>3
:For(Y,⁻1,1
 :Disp sum(seq((5-real(AnsX+AnsY)-3imag(AnsX+AnsY))₁₀^(X+1),X,⁻1,1
:End

```

Input is a number in `Ans`.

# Task 7 in 36 43 bytes

```
:Input <strike>L₁</strike>Str1
:.5
:For(I,1,<strike>dim(L₁</strike>length(Str1
 :Ans+<strike>L₁(I</strike>expr(sub(Str1,I,1
 :If 10=int(Ans
  :0
:End
:not(Ans

```

Prompts for a list of digits string.

# Task 9 in 83 bytes

```
:For(I,1,16,2
 :If I<8
  :Ans+sub(")}]>",inString("({[<",sub(Ans,4,1)),1
 :sub(Ans,I,1)+Ans
:End
:For(I,⁻1,1
 :Disp sub(Ans,9-8abs(I),8
:End

```

Input is a string in `Ans`.

# Task 10 in 159 bytes

```
:1→X
:Input Str1
:2+length(Str1→L
:"X
:While 2+L>length(Ans
 :Ans+Ans→Str2
:End
:Ans→Str3
:While 1
 :"XX
 :Ans+Str1+Ans→Str1
 :For(I,1,L
  :Ans+sub("0X.",2expr(sub(Str2,I+1,1))+not(expr(sub(Ans,I,3)+sub(Str2,I,3)+sub(Str3,I,3))),1
 :End
 :Disp sub(Ans,L+3,L
 :Str2→Str3
 :Str1→Str2
 :Input Str1
:End

```

Uses `X0.` instead of `.Xo` respectively (sorry nothing matches). Prompts for input line by line. You have to enter two lines of `X`s to see all the output, and then 2nd+Quit to quit.

# Task 12 in 77 bytes

```
:Ans+"tvm_I%LinReg(ax+b) DS<(getKeyconj(1-PropZTest(dayOfWk(Manual-Fit C/YANOVA(*row(HorizRegEQUnarchive [J]!#$&'',.234567890:;=>?@GBQX\^_`qw{|}~

```

Or as hex:

```
72702ABB21FFDBADBB25BB3EEF06EF16
6331BB5917746201BB695C092DBBD2BB
D3BBD4AEAE2B3A323334353637383930
3EBBD66A6CAFBBD147425158BBD7F0BB
D9BBD5BBC1BBC708BBD809BBCF

```

Input is a string containing `"` in `Ans`.

# Answer
> 7 votes
# Perl, 4 tasks in 117 bytes

Let's try a *real* language ;)

Haven't given up yet, might even be able to squeeze 5 tasks in 140 bytes, although unlikely!

### * Task 1: 30+1 = 31 bytes

```
@F=sort@F;say$F[0]+$F[1]>$F[2]

```

Usage: `perl -aM5.010 entry.pl input.txt`

### * Task 4: 32+1 = 33 bytes

```
y/ELTFHI/4223/;s/./+$&/g;$_=eval

```

Usage: `perl -p entry.pl input.txt`

### Task 5: 54 bytes

```
say"Alex "x($_/2+1).qw(A. .A)[$_%2]." xelA"x(--$_/2+1)

```

*-2b thanks to Dom Hastings*

Usage: `echo 4 | perl -M5.010 entry.pl`

### Task 7: 37+2 = 39 bytes

```
($i+=$_)>10&&exit,$i%=10for@F;$_=!$i;

```

Usage: `perl -pF entry.pl input.txt`

### * Task 8: 21+2 = 23 bytes

```
$_=y/|_
/14/dr/64%14

```

This is a bit of a tricky one. Started out by replacing each `|` with `x` and each `_` with `y` then replacing spaces to produce a unique two digit string for each grid (`yyxxyxxyyx`, `yyxxyxxyyxyyxxxxyxyx`, `yyxxxxyxyxyyxyxxxyyx`, `yyxyxxxyyxyyxxxxyyx`, `yyxxxxyyx`). Next, I wrote a program to bruteforce values for `x` and `y`, and mathematical operations that could be done on the numbers produced after substituting `x` and `y` to give an output of 3,6,9,12 for each number. In the end, `x=1`, `y=4` and the magic operation was `/64%14`.

Usage: `perl -0p entry.pl input.txt`

### Task 11: 34 bytes

```
say"SATOR
AREPO
TENET
OPERA
ROTAS"

```

Usage: `perl -M5.010 entry.pl`

### * Task 12: 30 bytes

```
say d.pack"C*",32..126,83..126

```

Usage: `perl -M5.010 entry.pl`

Disclaimer: `-M5.010` is considered 'free'

# Answer
> 6 votes
# Ruby, 4 tasks in 280 bytes (non-competitive)

This is just an attempt, I'll keep making tasks later (and hopefully golf the existing ones).

# Task 1

```
a=gets.split.map &:to_i;p a.all?{|e|e<a.inject(:+)-e}

```

# Task 2

```
p gets.chars.permutation.map{|a|a.join.to_i}.min_by{|x|(x-1e6).abs}

```

# Task 4

```
n,b='EFHILT',0;gets.chars.map{|c|b+=n[c]==p ? 0:[4,3,3,3,2,2][n.index c]};p b

```

# Task 5

```
a='Alex A.';gets.to_i.times{|i|i%2<1 ? a.sub!('A.','.A xelA'):a.sub!('.A',a)};$><<a

```

# Answer
> 6 votes
# TI-BASIC, 4 tasks in 114 bytes

Download all as a TI group file (.8xg)

(Spoiler tags added per request.)

## Task 1 - Can Three Numbers Form A Triangle? - 7 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :2max(Ans)`<`sum(Ans
> ```

## Task 4 - FILTHE Letters - 34 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :sum(int(`\`³√(`\`12seq(inString("TLIHFE",sub(Ans,X,1)),X,1,length(Ans
> ```

## Task 8 - Square Clock - 35 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :12-3max(seq(X(sub(Ans,6gcd(X,2)+X,1)≠" "),X,1,3
> ```

## Task 11 - Sator Square - 38 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :Disp "SATOR","AREPO","TENET","OPERA
> :"ROTAS
> ```

---

Bonus round! Here are all the other tasks just for fun.

## Task 2 - Closest To One Million - 114 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :int(10fPart(Ans`\`10^(`\`-cumSum(binomcdf(6,0→X
> :"sum(`\`L`\`X`\`10^(`\`cumSum(not(binompdf(6,0→`\`Y1`\`
> :SortD(`\`L`\`X
> :`\`Y1`\`→X
> :sum(not(`\`L`\`X
> :If Ans
> :Then
> :If max(`\`L`\`X=1
> :X+`\`E`\`6-`\`10^(`\`6-Ans→X
> :SortA(`\`L`\`X
> :augment(ΔList(cumSum(`\`L`\`X)),{0→X
> :End
> :{X,`\`Y1`\`
> :Ans(1+(0`>`min(ΔList(abs(`\`E`\`6-Ans
> ```

## Task 3 - Simple Keyboard Simulator - ~~131~~ 127 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :Input Str1
> :~~DelVar X~~1→Y
> :"..→Str2
> :For(Z,1,length(Str1
> :sub(Str1,Z,1→Str3
> :(Ans="`>`")-(Ans="`<`
> :If Ans
> :Then
> :max(1,min(Y+Ans,X+1→Y
> :Else
> :sub(Str2,1,Y)+Str3+sub(Str2,Y+1,X-Y+2→Str2
> :X+1→X
> :Y+1→Y
> :End
> :End
> :sub(Str2,2,X
> ```

## Task 5 - Alex Recursive A. - 107 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :Input X
> :".A..
> :For(X,0,X
> :Ans→Str1
> :5int(.5X+.5
> :sub(Str1,1,Ans+1)+sub(".A xelAlex A.",6gcd(X,2)-5,7)+sub(Str1,Ans+4,5X-Ans+1
> :End
> :sub(Ans,2,5X+2
> ```

## Task 6 - Numpad Rotation - 86 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :.3Ans+2(Ans=6→X
> :[[9,6,3][8,5,2][7,4,1
> :For(X,0,X
> :rowSwap(Ans`\`^T`\`),1,3
> :End
> :Ans
> :*row+(10,*row+(10,Ans`\`^T`\`,1,2),2,3
> :For(X,1,3
> :Disp Ans(3,X
> :End
> ```

## Task 7 - Splitting Digits Into Tens - 77 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :Ans+"0
> :seq(expr(sub(Ans,X,1)),X,1,length(Ans
> :augment(Ans,{10not(not(max(Ans→X
> :1→X
> :Repeat Ans≥dim(`\`L`\`X
> :Ans+1
> :If 10=sum(`\`L`\`X,X,Ans
> :Ans+1→X
> :End
> :X=Ans
> ```

## Task 9 - Bracket Art - 86 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :Input Str1
> :For(X,1,4
> :For(Y,0,1
> :abs(X-9not(Y→Z
> :"()[]{}`<>`
> :sub(Ans,inString(Ans,sub(Str1,X,1))+Y,1
> :Output(1,Z,Ans
> :Output(2,9-Z,Ans
> :Output(3,Z,Ans
> :End
> :End
> ```

## Task 10 - Perimiterize - 218 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :".
> :For(A,0,`\`E`\`9
> :Input Str1
> :Ans+Str1→Str2
> :If Str1≠".
> :End
> :length(Ans→X
> :round(A`\`^-1`\`(Ans-2→B
> :seq(expr(sub(Str2,A,1)),A,2,X-1→B
> :πAns→C
> :"augment(Ans,augment(Ans,`\`L`\`B))+augment(Ans,augment(`\`L`\`C,Ans))+augment(`\`L`\`B,augment(Ans,Ans→X
> :seq(0,A,1,B
> :`\`L`\`X→A
> :For(C,0,A+1
> :seq(`\`L`\`A(A+BC),A,1,B→C
> :int(Ans→B
> :{0
> :1+not(`\`L`\`X)+not(fPart(`\`L`\`X→B
> :".
> :For(X,1,B+2
> :Ans+sub("120",`\`L`\`B(X),1
> :End
> :Disp sub(Ans,2,B+2
> :End
> ```

These substitutions have been made: `0`=`.`, `1`=`X`, `2`=`o`

For input (after the program begins), type one row at a time, pressing enter at each line break, until the last row is written out. Then press enter, type one period, then hit enter again to submit the entire string.

## Task 12 - Prime Tweet - 151 bytes

Download as a TI-83+ program file (.8xp)

> ```
> :Ans+"!#$%`&`'()*+,-./01234567889:;`<`=`>`?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[`\`]^_`abcdefghijklmnopqrstuvwxyz{|}~
> :For(X,1,45
> :Ans+"
> :End
> :Ans
> ```

`Ans` should contain a double quote, performed by typing one directly into `\Y1\` from the equation editor and running `Equ►String(\Y1\,Str1:Str1` from the home screen.

The output length is 140. 8 appears twice, and there are 45 spaces along with the other ASCII characters each appearing once. This amounts to (33+34+...+126) + 56 + 32×45 = 8969, a Sophie Germain prime.

# Answer
> 0 votes
## Python 3, 1 task, 268 bytes, non-competitive

I tried Task #2 in Python 3.5.2 I am new to code golfing and python

```
import itertools
def f2(l):
    n=1000000
    l=list(itertools.permutations(l))
    j = len(l)
    m=[None]*j
    while j>0:
        j -= 1
        m[j]= int(''.join(str(i) for i in l[j]))
        l[j]=abs(n-m[j])
    l.sort()
    k=n-l[0]
    return(n+l[0],k)[k in m]

```

---
Tags: code-golf, string, number, arithmetic, multiple-holes
---


title: Bootloader golf: Brainf***

text:
# Question
Title: Bootloader golf: Brainf***
Create a bootloader that executes given Brainfuck program. This is , so the program with least bytes wins. Being a bootloader, the size of the program is counted in non-zero bytes in the compiled code.

## Brainfuck

30000 8-bit overflowing cells. Pointer wraps over.

Some notes about operations:

* Input must be read in a way that all printable ASCII characters are correctly supported. Other keystrokes may either insert an arbitrary character or do nothing at all.
* Reading user input must be character buffered, not line buffered.
* Reading user input must echo inserted character.
* Output must follow either the code page 437 or your built-in VGA adapters default codepage.

## Bootloader

This is a x86 bootloader. A bootloader ends with the traditional `55 AA` sequence. Your code must run either on VirtualBox, Qemu or other well-known x86 emulator.

## Disk

Executable Brainfuck is located at second disk sector, right after your bootloader, which is placed, as usually, in MBR section, the first sector on disk. Additional code (any code over 510 bytes) can be located at other disk sectors. Your storage device must be either a hard drive or a floppy disk.

## STDIO

Of course, a bootloader cannot have an access to the operating system's IO capabilities. Therefore BIOS functions are used instead for printing text and reading user input.

## Template

To get started, here is a simple template written in Nasm (intel syntax) assembly:

```
[BITS 16]
[ORG 0x7c00]

; first sector:

boot:
    ; initialize segment registers
    xor ax, ax
    mov ds, ax
    mov es, ax
    mov ss, ax

    ; initialize stack
    mov sp, 0x7bfe

    ; load brainfuck code into 0x8000
    ; no error checking is used
    mov ah, 2       ; read
    mov al, 1       ; one sector
    mov ch, 0       ; cylinder & 0xff
    mov cl, 2       ; sector | ((cylinder >> 2) & 0xc0)
    mov dh, 0       ; head
                    ; dl is already the drive number
    mov bx, 0x8000  ; read buffer (es:bx)
    int 0x13        ; read sectors

; fill sector
times (0x200 - 2)-($-$$) db 0

; boot signature
db 0x55, 0xaa

; second sector:

db 'brainfuck code here'

times 0x400-($-$$) db 0

```

Compiling this is pretty easy:

```
nasm file.asm -f bin -o boot.raw

```

And the run it. For example, with Qemu:

```
qemu-system-i386 -fda boot.raw

```

---

Addtional information: OsDev wiki, Wikipedia

# Answer
> 13 votes
# 171 bytes1

Wooohoooo! It took half the day, but it was fun...

So, here it is. I think it conforms to the specs (wraparound of cell pointer, echo of characters on input, reading char by char, echo of input chars, ...), and it seems to actually work (well, I didn't try many programs, but given the simplicity of the language, the coverage isn't that bad, I think).

## Limitations

One important thing: if your brainfuck program contains other chars than the 8 brainfuck instructions, or if the `[]` are not well-balanced, *it will crash on you, mouhahahaha!*

Also, the brainfuck program can't exceed 512 bytes (a sector). But this seems conforming since you say *"executable Brainfuck is located at second disk sector"*.

Last detail: I didn't explicitly initialized the cells to zero. Qemu seem to do it for me, and I'm relying on this, but I don't know whether a real BIOS on a real computer would do it (initialization would just take a few bytes more, anyway).

## The code

(based on your template, and by the way, thanks for this, I would never have tried without it):

```
[BITS 16]
[ORG 0x7C00]

%define cellcount 30000 ; you can't actually increase this value much beyond this point...

; first sector:

boot:
    ; initialize segment registers
    xor ax, ax
    mov ss, ax
    mov ds, ax
    mov es, ax
    jmp 0x0000:$+5

    ; initialize stack
    mov sp, 0x7bfe

    ; load brainfuck code into 0x8000
    ; no error checking is used
    mov ah, 2       ; read
    mov al, 1       ; one sector
    mov ch, 0       ; cylinder & 0xff
    mov cl, 2       ; sector | ((cylinder >> 2) & 0xc0)
    mov dh, 0       ; head
                    ; dl is already the drive number
    mov bx, 0x8000  ; read buffer (es:bx)
    int 0x13        ; read sectors

    ; initialize SI (instruction pointer)
    mov si, bx ; 0x8000
    ; initialize DI (data pointer)
    mov bh, 0x82
    mov di, bx ; 0x8200

decode:
    lodsb ; fetch brainfuck instruction character
.theend:
    test al, al ; endless loop on 0x00
    jz .theend
    and ax, 0x0013 ; otherwise, bit shuffling to get opcode id
    shl ax, 4
    shl al, 2
    shr ax, 1
    add ax, getchar ; and compute instruction implementation address
    jmp ax

align 32, db 0

getchar:
    xor ah, ah
    int 0x16
    cmp al, 13
    jne .normal
    mov al, 10 ; "enter" key translated to newline
.normal:
    mov byte [di], al
    push di
    jmp echochar

align 32, db 0

decrementdata:
    dec byte [di]
    jmp decode

align 32, db 0

putchar:
    push di
    mov al, byte [di]
echochar:
    mov ah, 0x0E
    xor bx, bx
    cmp al, 10 ; newline needs additional carriage return
    jne .normal
    mov al, 13
    int 0x10
    mov al, 10
.normal:
    int 0x10
    pop di
    jmp decode

align 32, db 0

incrementdata:
    inc byte [di]
    jmp decode

align 32, db 0

decrementptr:
    dec di
    cmp di, 0x8200 ; pointer wraparound check (really, was that necessary?)
    jge decode
    add di, cellcount
    jmp decode

align 32, db 0

jumpback:
    pop si
    jmp jumpforward

align 32, db 0

incrementptr:
    inc di
    cmp di, 0x8200+cellcount  ; pointer wraparound check
    jl decode
    sub di, cellcount
    jmp decode

align 32, db 0

jumpforward:
    cmp byte [di], 0
    jz .skip
    push si
    jmp decode
.skip:
    xor bx, bx ; bx contains the count of [ ] imbrication
.loop:
    lodsb
    cmp al, '['
    je .inc
    cmp al, ']'
    jne .loop
    test bx, bx
    jz decode
    dec bx
    jmp .loop
.inc:
    inc bx
    jmp .loop

; fill sector
times (0x1FE)-($-$$) db 0

; boot signature
db 0x55, 0xAA

; second sector contains the actual brainfuck program
; currently: "Hello world" followed by a stdin->stdout cat loop

db '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.,[.,]'

times 0x400-($-$$) db 0

```

## Tricks used

Ok, I cheated a bit. Since you said *"being a bootloader, the size of the program is counted in non-zero bytes in the compiled code"*, I made the code smaller by allowing "holes" between the implementation of the eight brainfuck opcodes. This way, I don't need a big sequence of tests, a jump table, or anything: I just jump to the brainfuck "opcode id" (from 0 to 8) multiplied by 32 to execute the brainfuck instruction (worth to note that it means the implementation of the instructions can't take more than 32 bytes).

Moreover, to get this "opcode id" from the brainfuck program character fetched, I noticed just a bit of bit shuffling was necessary. Indeed, if we just consider bits 0, 1 and 4 of the opcode character, we end up with the 8 unique combinations:

```
   X  XX
00101100 0x2C , Accept one byte of input, storing its value in the byte at the pointer.
00101101 0x2D - Decrement (decrease by one) the byte at the pointer.
00101110 0x2E . Output the value of the byte at the pointer.
00101011 0x2B + Increment (increase by one) the byte at the pointer.
00111100 0x3C < Decrement the pointer (to point to the next cell to the left).
01011101 0x5D ] Jump back after the corresp [ if data at pointer is nonzero.
00111110 0x3E > Increment the pointer (to point to the next cell to the right).
01011011 0x5B [ Jump forward after the corresp ] if data at pointer is zero.

```

And, lucky me, there is actually one opcode that requires more than 32 bytes to implement, but it's the last one (jump forward `[`). As there is more room after, everything is fine.

Other trick: I don't know how a typical brainfuck interpreter works, but, to make things much smaller, I did not actually implement `]` as *"Jump back after the corresponding `[` if data at pointer is nonzero"*. Instead, I *always* go back to the corresponding `[`, and, from here, re-apply the typical `[` implementation (which then, eventually, goes forward after the `]` again if needed). For this, each time I encouter a `[`, I put the current "brainfuck instruction pointer" on the stack before executing the inner instructions, and when I encounter a `]`, I pop back the instruction pointer. Pretty much as if it was a call to a function. You could therefore theoretically overflow the stack by making many many imbricated loops, but not with the current 512-bytes limitation of the brainfuck code, anyway.

---

1. Including the zero bytes that were part of the code itself, but not those that were part of some padding

---
Tags: code-golf, brainfuck, assembly, machine-code, x86-family
---


title: Numbers x such that x^2 divides 7^x-1

text:
# Question
Title: Numbers x such that x^2 divides 7^x-1
# Task

There is a set of numbers `x`, such that `x^2` divides `7^x-1`.

Your task is to find these numbers. Given an input of n, the code will print the nth number that follows this rule.

# Examples 1-index

```
In   Out
3    3
9    24
31   1140

```

The relevant sequence can be found here.

## Rules

Shortest answer will be the winner\*

Standard golfing rules apply

Loopholes are not allowed

Your answer can either be 0 or 1 indexed, please state in your answer

# Answer
## Haskell, 34 bytes

```
([x|x<-[1..],mod(7^x-1)(x^2)<1]!!)

```

This uses 0-based indexing. Usage example: `([x|x<-[1..],mod(7^x-1)(x^2)<1]!!) 30` -\> `1140`.

It's a direct implementation of the definition. It builds a list of all numbers `x` and picks the `n`th.
> 7 votes

# Answer
# Pyth, 10 bytes

```
e.f!%t^7Z*

```

A program that takes input of an integer and prints a one-indexed value.

Try it online!

**How it works**

```
e.f!%t^7Z*     Program. Input: Q
e.f!%t^7Z*ZZQ  Implicit variable fill
               Implicitly print
e              the last
 .f         Q  of the first Q positive integers Z
     t^7Z      for which 7^Z - 1
    %          mod
         *ZZ   Z^2
   !           is zero

```
> 5 votes

# Answer
# JavaScript (ES7), 40 bytes

```
f=(n,i=1)=>n?f(n-!((7**++i-1)%i**2),i):i

```

This loses precision fairly quickly due to the fact that JS loses precision by `7**19`. Here's a nearly arbitrary-precision ES6 version:

```
f=(n,i=0)=>n?f(n-!(~-(s=++i*i,g=j=>j?g(j-1)*7%s:1)(i)%s),i):i

```

This finishes within about a second for test case 31.

A few longer approaches:

```
f=(n,i=0)=>n?f(n-!(~-(s=>g=j=>j?g(j-1)*7%s:1)(++i*i)(i)%s),i):i
f=(n,i=0)=>n?f(n-!(s=++i*i,g=(j,n=1)=>j?g(j-1,n*7%s):~-n%s)(i),i):i
f=(n,i=0)=>n?f(n-!(s=>g=(j,n=1)=>j?g(j-1,n*7%s):~-n%s)(++i*i)(i),i):i

```
> 5 votes

# Answer
# 05AB1E, 11 bytes

```
µ7Nm<NnÖiN¼

```

Try it online!

For some reason I can't get `½` to work in `µ7Nm<NnÖ½N` or I'd be tied with Pyth.

```
µ           # Loop until the counter equals n.
 7Nm<       # Calc 7^x+1.
     Nn     # Calc x^2.
       Ö    # Check divisibility.
        iN¼ # If divisible, push current x and increment counter.
            # Implicit loop end.
            # Implicitly return top of stack (x)

```

.
> 4 votes

# Answer
# Python 2, ~~48~~ 46 bytes

*Thanks to @Dennis for -2 bytes!*

```
f=lambda n,i=1:n and-~f(n-(~-7**i%i**2<1),i+1)

```

A one-indexed recursive function that takes input via argument and returns the result.

Try it online! (Recursion limit increased to allow the final test case to run)

**How it works**

`n` is the desired index, and `i` is the counting variable.

The expression `~-7**i%i**2<1` returns `True` (equivalent to `1`) if `i^2` divides `7^i - 1`, and `False` (equivalent to `0`) otherwise. Each time the function is called, the result of the expression is subtracted from `n`, decrementing `n` each time a hit is found; `i` is also incremented.

The short-circuiting behaviour of `and` means that when `n` is `0`, `0` is returned; this is the base case. Once this is reached, recursion stops, and the current value of `i` is returned by the original function call. Rather than explicitly using `i`, this is done using the fact that for each function call, an increment has been performed using the `-~` in front of the call; incrementing `0` `i` times gives `i`, as required.
> 4 votes

# Answer
# Python 2, ~~57~~ ~~53~~ 51 bytes

-4 bytes thanks to ETHproductions
-2 bytes thanks to TuukkaX

```
i=0
g=input()
while g:i+=1;g-=~-7**i%i**2<1
print i

```

Try it online!
the sequence is 1-indexed
> 3 votes

# Answer
# Python 2, 57 bytes

This takes a really, *really* long time for large values. It also uses plenty of memory, because it builds the entire list way farther than necessary. The result is zero-indexed.

```
lambda n:[x for x in range(1,2**n+1)if(7**x-1)%x**2<1][n]

```

**Try it online**
> 2 votes

# Answer
## Mathematica, 43 bytes

I've currently got three different solutions at this byte count:

```
Nest[#+1//.x_/;!(x^2∣(7^x-1)):>x+1&,0,#]&
Nest[#+1//.x_/;Mod[7^x-1,x^2]>0:>x+1&,0,#]&
Nest[#+1//.x_:>x+Sign@Mod[7^x-1,x^2]&,0,#]&

```
> 2 votes

# Answer
# PARI/GP, 42 bytes

Pretty straightforward. 1-indexed, though this could easily be changed.

```
n->=k=1;while(n--,while((7^k++-1)%k^2,));k

```

or

```
n->=k=1;for(i=2,n,while((7^k++-1)%k^2,));k

```
> 2 votes

# Answer
# Python 3, 45 bytes

```
f=lambda n,k=2:n<2or-~f(n-(7**k%k**2==1),k+1)

```

Return *True* for input **1**, which is allowed by default.

Try it online!
> 1 votes

# Answer
# R, 35 bytes

This only works for `n<=8`.

```
z=1:20;which(!(7^z-1)%%z^2)[scan()]

```

However, here's a longer version which works for `n<=25`, for **50 bytes**:

```
z=1:1e6;which(gmp::as.bigz(7^z-1)%%z^2==0)[scan()]

```
> 1 votes

# Answer
# Perl 6, ~~35~~ 34 bytes

```
{grep({(7**$_-1)%%$_²},^∞)[$_]}

```

0-indexed.

Shaved off one byte thanks to Brad Gilbert.
> 0 votes

# Answer
# PHP, ~~47~~ 49 bytes

```
while($n<$argv[1])$n+=(7**++$x-1)%$x**2<1;echo$x;

```

Only works for n\<9 (`7**9` is larger than `PHP_INT_MAX` with 64bit)

**62 bytes** using arbitrary length integers: (not tested; PHP on my machine doesn´t have bcmath)

```
for($x=$n=1;$n<$argv[1];)$n+=bcpowmod(7,++$x,$x**2)==1;echo$x;

```

Run with `php -nr '<code>' <n>`.

**pseudo code**

```
implicit: $x = 0, $n = 0
while $n < first command line argument
    increment $x
    if equation is satisfied
        increment $n
print $x

```
> 0 votes

# Answer
## Pyke, 10 bytes

```
~1IX7i^tR%

```

Try it here!

```
~1         -  infinite(1)
  IX7i^tR% - filter(^, not V)
    7i^    -    7**i
       t   -   ^-1
        R% -  ^ % v
   X       -   i**2
           - implicit: print nth value

```
> 0 votes

# Answer
# Clojure, 83 bytes

```
(fn[n](nth(filter #(= 0(rem(-(reduce *(repeat % 7N))1)(* % %)))(iterate inc 1N))n))

```

Try it online!

This builds an infinite list of Java BigIntegers starting at 1 and filters them by the definition. It uses zero-based indexing to select the *nth* value from the filtered list.
> 0 votes

# Answer
# Perl 5, 35 Bytes

Well, this was missing, so here it is:

`map{$_ if!((7**$_-1)%($_**2))}1..<>`
> 0 votes

# Answer
# Powershell, too many bytes

Just to see if it was possible and it is.

```
[System.Linq.Enumerable]::Range(1,10000)|?{[System.Numerics.BigInteger]::Remainder([System.Numerics.BigInteger]::Pow(7,$_)-1,$_*$_) -eq 0}

```
> 0 votes

# Answer
## QBIC, 39 bytes

```
:{~(7^q-1)%(q^2)=0|b=b+1]~b=a|_Xq\q=q+1

```

I couldn't get it to run in QBasic 4.5, but it seems to run fine in QB64. For some inexplicable reason, QBasic refuses to cleanly divide 13,841,287,200 by 144, but instead gives a remainder of -128. It then returns 16 as the 7th term of this sequence instead of 12...

```
:{      get N from the command line, start an infinite DO-loop
~       IF
(7^q-1) Part 1 of the formula (Note that 'q' is set to 1 as QBIC starts)
%       Modulus
(q^2)   The second part
=0      has no remainder
|b=b+1  Then, register a 'hit'
]       END IF
~b=a    If we have scored N hits
|_Xq    Quit, printing the last used number (q)
\q=q+1  Else, increase q by 1.
        [DO-loop and last IF are implicitly closed by QBIC]

```
> 0 votes

# Answer
# Wonder, 28 bytes

```
@:^#0(!>@! % - ^7#0 1^#0 2)N

```

Zero-indexed. Usage:

```
(@:^#0(!>@! % - ^7#0 1^#0 2)N)2

```

Filters from the list of natural numbers with a predicate that determines whether `x^2` is divisible by `7^x-1`, then gets the nth item in that list.
> 0 votes

# Answer
# Tcl, 73 bytes

```
while {[incr i]} {if 0==(7**$i-1)%$i**2 {incr j;if $j==$n break}}
puts $i

```

Try it online!
> 0 votes

---
Tags: code-golf, math, sequence
---


title: Springify a String

text:
# Question
Title: Springify a String
Sandbox post here.

Create a function or program that "Springifies" a string.

* Input will be a String in Stdin, or closest alternative
* Input will only contain printable ASCII and/or spaces
* Output will be to Stdout, or closest alternative
* A trailing newlines and spaces are acceptable

### How to springify a String

1. Format the String into as many ASCII spring coils as needed
2. Pad the coils with spaces, up to the nearest coil
3. Read off the characters, following the spring around the coils

This is an ASCII spring coil:

```
#
# ####
 #    #
# ####
#

```

Where the `#`s are the characters of the String

Here is an example:

`abcdefghijklmnopqrstuvwxyz`

becomes

```
a
b cdef
 g    h
i jklm
n
o
p qrst
 u    v
w xyz.
.

```

Where the `.`s replace spaces for visibility.

Then, the string is read back, following the ASCII spring downwards, around the loops, hitting the `g` and `u` twice:

```
1| a  <-3
 V b cdef
    g    h
4| i jklm
 V n  2->
  ...

```

...giving:

`abgjklmhfedcginopuxyz vtsrquw` (with a trailing space)

### Test Cases

(quotations added to highlight trailing spaces - please ignore in terms of IO)

```
I: "abcdefghijklmnopqrstuvwxyz"
O: "abgjklmhfedcginopuxyz vtsrquw "

I: "!@#"
O: "!@         #   "

I: ""
O: ""

I: "12345 67890"
O: "12690  7 54368 "

I: " "
O: "               "

```

Note that the output length is always a multiple of 15, the length of a spring coil

This is , so the shortest answer in bytes wins.

# Answer
> 2 votes
# Jelly, 26 bytes

```
“4ṘƝ;þ¦Ɱ’b®¤ị
;⁶x14©¤s®ṖÇ€

```

**TryItOnline!**

### How?

```
“4ṘƝ;þ¦Ɱ’b®¤ị - Link 1, output for a single coil: char array
           ¤  - nilad followed by link(s) as a nilad
“4ṘƝ;þ¦Ɱ’     - base 250 number, 13140239220751650
          ®   - retrieve from register (14 from main link)
         b    - convert to base, [1,2,7,10,11,12,13,8,6,5,4,3,7,9,0]
            ị - index into the char array

;⁶x14©¤s®ṖÇ€ - Main link: theString
      ¤      - nilad followed by link(s) as a nilad
 ⁶           - a space character
  x          - repeated
   14©       - place 14 into the register and yield 14
;            - concatenate theString with the 14 spaces
       s     - split into chunks of length
        ®    -     retrieve from register (14)
         Ṗ   - pop last entry from the result (removes the space only last entry of 14 chars or less)
          Ç€ - call the last link (1) as a monad for €ach
             - implicit print

```

# Answer
> 5 votes
# Python 2, ~~104~~ ~~102~~ 98 Bytes

```
f=lambda t:''.join((t+' '*13)[ord(x)-97+y*14]for y in range(len(t)/14+1)for x in'abgjklmhfedcgin')

```

Thanks for the comment help!

https://tio.run/#2VDVy

Original:

```
t=raw_input()+' '*13
print''.join(t[ord(x)-97+y*14]for y in range(len(t)/14)for x in'abgjklmhfedcgin')

```

# Answer
> 3 votes
## JavaScript (ES6), 79 bytes

```
f=
s=>s.replace(/.{1,14}/g,s=>'0169abc7543268d'.replace(/./g,c=>s['0x'+c-0]||' '))
```

```
<input oninput=o.textContent=f(this.value)><pre id=o>
```

Hexadecimal string shamelessly stolen from @ETHproductions.

# Answer
> 2 votes
# JavaScript (ES7), ~~144~~ ~~143~~ ~~141~~ ~~114~~ ~~104~~ 103 bytes

*Thanks to ETHProductions for a 10B save!*

```
a=>[...b=a+' '.repeat(15-a.length%15)].map((_,c)=>b['0x'+'0169abc7543268d'[c%15]-0+(c/15|0)*14]).join``

```

## Example

```
f=a=>[...b=a+' '.repeat(15-a.length%15)].map((_,c)=>b['0x'+'0169abc7543268d'[c%15]-0+(c/15|0)*14]).join``
f('abcdefghijklmnopqrstuvwxyz')

```

## Output

```
abgjklmhfedcginopuxyz vtsrquw

```

# Answer
> 2 votes
## Retina, 71 bytes

```
$
13$*
M!`.{14}|$
(.)(.)(.)(.)(.)(.)(.)(....)(.)¶
$5$8$6$4$3$2$1$5$7$9

```

Try it online!

Permuting strings isn't exactly concise in Retina...

# Answer
> 2 votes
# Perl 6, 61 bytes

```
{S:g/(.)**1..14/{[~] $0["abgjklmhfedcgin".ords X-97]X//" "}/}

```

### How it works

The basic structure is this:

```
{                                  }  # A lambda.
 S:g/(.)**1..14/{                }/   # Regex-replace segments of 1-14 characters, with:
                     $0               #   The single-char submatches captured by the parens.
                       [  ]           #   Index them using certain indices (see below).
                           X//" "}    #   Replace each undefined element with a space.
                 [~]                  #   Concatenate the characters.

```

The expression used to index into each 14-characters segment is `"abgjklmhfedcgin".ords X- 97`, which works as follows:

1. Take the hard-coded string `abgjklmhfedcgin`.
2. Get its codepoints: `97 98 103 106 107 108 109 104 102 101 100 99 103 105 110`.
3. Subtract 97 from each number: `0 1 6 9 10 11 12 7 5 4 3 2 6 8 13`.

---

# Perl 6, 64 bytes

```
{[~] .comb(14)».comb»[0,1,6,9..12,7,5...2,6,8,13].flat X//" "}

```

Try it online!

### How it works

The basic structure is this:

```
{                                    }  # A lambda.
     .comb(14)                          # Split the argument into substrings of <= 14 chars.
              ».comb                    # Split each substring into a list of characters.
                    »[  ]               # Index each list using the same indices (see below).
                         .flat          # Flatten the resulting nested list.
                               X//" "   # Replace each undefined element with a space.
 [~]                                    # Concatenate the list to get a string again.

```

Same indices as above, but since we're calling `.flat` anyway, we can use a nested (but 1 byte shorter) expression for them: `0,1,6,9..12,7,5...2,6,8,13`.

(Looks trivial, but actually relies on a parsing peculiarity of Rakudo Perl 6 that is probably a bug. To write it without exploiting that bug, one would have to add parens around the `5...2`.)

# Answer
> 2 votes
# Befunge-93, 97 bytes

```
<>0>v%2g3\p89:-1+*"!"!:+1<_@#`0:~
,^\,_\:98g\9p1+:76+`#v_:~^
^,,g96g98g9+67,,,,,$$_
==    =  ====

```

Try it online!

This is a breakdown of the source code with the various component parts highlighted.

The main loop starts off executing right to left, wrapping around to the right hand side of the playfield. This is where we read the first character from stdin, and terminate if it's an EOF.
The next section makes sure any EOF characters are converted to spaces using the formula `c = c + 31*!(c+1)`. Although this won't apply on the first iteration, it can occur on subsequent passes.
A copy of the character is saved to temporary memory, and then a lookup of the current index is performed on the table on line four () to determine whether the character should be output or not.
If the character needs to be output, we take the left branch. A swap is performed here to cancel out the swap that's going to occur next, and then a zero is pushed to force the branch right.
If the character wasn't output, we swap it down the stack beneath the index counter (this is the swap that gets cancelled in the left branch). And in both cases we save the character to memory at the current index offset, increment the index, and check if it's greater than 13.
If not, we read the next character from stdin and repeat the inner loop.
If it is, we'll have finished a set of 14 characters, 7 having been output (`abgjklm`), and 7 remaining on the stack (`cdefhin`). We drop the last two, output the remaining 5 (`hfedc`), and then retrieve and output the special cases `g`, `i` and `n` from memory.
And that brings us back to the start of the main loop, where we repeat the process again for the next 14 characters.

# Answer
> 1 votes
# Mathematica, ~~77~~ 72 bytes

*Thanks to JungHwan Min for saving 5 bytes!*

```
Join@@Partition[#,14,14,{1,1}," "][[;;,LetterNumber@"abgjklmhfedcgin"]]&

```

Unnamed function taking a list of characters as input and returning a list of characters. `Partition[#,14,14,{1,1}," "]` splits the input into sublists of length 14, padding with spaces if necessary. `LetterNumber@"abgjklmhfedcgin"` evaluates to `{1,2,7,10,11,12,13,8,6,5,4,3,7,9,14}`, which indicates the order to take each length-14 sublist in (repeating the 7th element appropriately). Then `[[;;,...]]` takes the elements of all the length-14 sublists in that order, and `Join@@` joins the answers together.

Previous submission:

```
Join@@Partition[#,14,14,{1,1}," "][[All,83224017339955102~IntegerDigits~16]]&

```

# Answer
> 1 votes
# Python 3, 86 bytes

```
lambda s:''.join(t[i%14]for t in zip(*[iter(s+' '*13)]*14)for i in b'Tq>]zQ|1/X;:L$o')

```

Try it online!

As a bonus, the string `Tq>]zQ|1/X;:L$o` is a valid CJam program that prints the unique characters on standard input, sorted. Try it online! (+ explanation)

# Answer
> 0 votes
# PHP, 94 bytes

```
foreach(str_split($argv[1],14)as$s)for($i=0;$c=abgjklmhfedcgin[$i++];)echo$s[ord($c)-97]??" ";

```

splits command line argument to 14-byte chunks and loops through the translation string as index for the sub-string. Run with `php -nr '<code>' <string>`.

I was glad to find out that `??` also accepts the empty string (for an "invalid" index) as null.

# Answer
> 0 votes
## Ruby, 83 bytes

```
->s{v="";(s+" "*13).scan(/.{14}/){|y|"0169:;<7543268=".chars{|o|v+=y[o.ord-48]}};v}

```

First idea was using hex numbers, but ord-48 saves another byte (stolen from throx's answer).

---
Tags: code-golf, string
---