# Question
Title: What's the shortest contiguous subset of ASCII you need to output the rest?
The printable ASCII characters (hex codes 20 to 7E) in order are:

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

```

(Note that space is in there.)

This string clearly contains all the printable ASCII characters at least once in increasing order when read from left to to right, but not in decreasing order.

The string reversed:

```
~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"! NORMAL: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

```

contains all the printable ASCII characters at least once both in increasing *and* decreasing order. In other words, when the characters are valued with their numeric code, the longest increasing and longest decreasing subsequences have length 95 (the number of printable ASCII characters).

# Challenge

Choose a *contiguous* subset of N printable ASCII characters, such as `LMNOP` (N = 5). Write a program using only those N characters whose output contains all 95 ASCII characters in increasing *and* decreasing order like the example above.

The winner is the submission with the lowest N. In case of ties the shortest code in bytes wins.

# Notes

* A contiguous subset means a set of the printable ASCIIs that all appear in an unbroken line, such as `LMNOP` or `89:;<=>`.
* Your contiguous subset may "loop around" from `~` to space, but this incurs a +3 penalty on N. So `{|}~` has N = 4, but `{|}~ !` has N = 6 + 3 = 9.
* Your program may only contain the N printable ASCII characters from the contiguous subset you've selected. They do not all have to appear and may appear multiple times in any order. **(All non-printable ASCII and all non-ASCII is not allowed. This means tabs and newlines are not allowed.)**
* Your output may only contain printable ASCII characters and must be less than 10000 characters long.
* Your output's longest increasing and decreasing subsequences must both have length 95 (as explained above).
* Output to stdout. There is no input.
* N is a positive integer less than 96.

# Answer
> 36 votes
# Unary, N=1

# 14680262330376163203871465704220787333741951071 bytes

Uses only the '0' byte (ASCII 49).

Golfed about 4.1325279×1060 bytes out of @Comintern's solution. Credit still to him :)

In the original Brainfuck:

```
++++++++[->++++<]>
[>+>+++<<-]>>-
[-<.+<+>>]<<
[>-.<-]

```

# Answer
> 101 votes
## Unary, N=1

## 4132527913354820031118363262102424570092493175835499123283719 (4.1325279e+60) bytes

Source code in unary is obviously too large to post here. It can be easily reproduced by typing out (or generating) a file filled with "0"s of the same length as the number of bytes above.

Here is the binary representation:

```
1010010010010110011000010010010010010010010010001111000000010010010010010110011000010010010010010010010010010010010010010010010010010010010001111000110011001010001100010000000111001110011001011100000111

```

And the equivalent Brainf\**k code (linebreaks for clarity):

```
++++[->++++++++<]>>
+++++[->+++++++++++++++++++<]>
[-<+<.+>>]<
[-<-.>]

```

Output:

```
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!

```

**EDIT:** Golfed out 9.097887e+87 unnecessary characters.

# Answer
> 53 votes
# Brainfuck, N=2

```
----------------------------------------------------------------------------------------------------------------------------------.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.

```

24,383 bytes. Uses only - and . (ASCII 45 and 46). Try it here: http://esoteric.sange.fi/brainfuck/impl/interp/i.html. Can probably be parsed as Morse code with the right spaces.

Requires an interpreter adhering to the traditional definition of Brainfuck, which uses an array of (at least) 30,000 *byte* cells, all initialized to zero.

# Answer
> 25 votes
# CJam - N=3; 7659 bytes

```
''(((((((''((((((''(((((''((((''(((''((''('''(')'))')))'))))')))))'))))))')))))))'))))))))')))))))))'))))))))))')))))))))))'))))))))))))')))))))))))))'))))))))))))))')))))))))))))))'))))))))))))))))')))))))))))))))))'))))))))))))))))))')))))))))))))))))))'))))))))))))))))))))')))))))))))))))))))))'))))))))))))))))))))))')))))))))))))))))))))))'))))))))))))))))))))))))')))))))))))))))))))))))))'))))))))))))))))))))))))))')))))))))))))))))))))))))))'))))))))))))))))))))))))))))')))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))'))))))))))))))))))))))))))))')))))))))))))))))))))))))))'))))))))))))))))))))))))))')))))))))))))))))))))))))'))))))))))))))))))))))))')))))))))))))))))))))))'))))))))))))))))))))))')))))))))))))))))))))'))))))))))))))))))))')))))))))))))))))))'))))))))))))))))))')))))))))))))))))'))))))))))))))))')))))))))))))))'))))))))))))))')))))))))))))'))))))))))))')))))))))))'))))))))))')))))))))'))))))))')))))))'))))))')))))'))))')))'))')'(''''(''((''(((''((((''(((((''((((((''(((((((

```

Try it at http://cjam.aditsu.net/

# Answer
> 18 votes
# Brainf\**k, N=4

My first brainfuck program. Uses 3 characters out of the block `+,-.` (Ascii 43 to 46.)

410 bytes (one `.` can be deleted from the program if the double `~~` can be reduced to a single `~`.)

Here's the list of commands in that area of the ASCII table (I don't need the input command):

```
+   increment (increase by one) the byte at the data pointer.
-   decrement (decrease by one) the byte at the data pointer.
.   output the byte at the data pointer.
,   accept one byte of input, storing its value in the byte at the data pointer.

```

Fortunately the remaining commands `<>[]` (moving data pointer and performing conditional jumps) are not required!

Split into 3 lines for clarity: **1:** Increment until the data reaches 32. **2:** Output and increment until data reaches 126. **3:** Output and decrement until data reaches 32.

```
++++++++++++++++++++++++++++++++

.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.

.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.

```

Output

```
 !"#$%&'()*+,-./0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!

```

# Edit N=2

Per @nneonneo's answer, it is possible to replace each `+` with 255 `-`signs for N=2. some rearrangement of the code and output (displaying down then up) means the first line can be reduced to 256-126=130 `-` signs. This occurred to me after I went to bed, and nneoneo beat me to it. https://codegolf.stackexchange.com/a/35801/15599

# Answer
> 8 votes
# C; N = 43 = 40 + 3

Here I avoid such common characters as `+` `-` `*` `/`, the digits `0-9`, comma `,` and semicolon `;`.

So I was forced to express various numbers using only the operations `&` `%` `~`.

Further golfing may be possible (finding smallest representations for the numbers 63 and 95 is an exercise for the reader).

```
main(){
if (printf(" !"))
if (putchar('"'))
if (printf("#$%%&'"))
if (putchar('i'%(~' '&'a')))
if (putchar('j'%(~' '&'a')))
if (putchar('k'%(~' '&'a')))
if (putchar('l'%(~' '&'a')))
if (putchar('m'%(~' '&'a')))
if (putchar('n'%(~' '&'a')))
if (putchar('o'%(~' '&'a')))
if (putchar('p'%(~' '&'a')))
if (putchar('q'%(~' '&'a')))
if (putchar('r'%(~' '&'a')))
if (putchar('s'%(~' '&'a')))
if (putchar('t'%(~' '&'a')))
if (putchar('u'%(~' '&'a')))
if (putchar('v'%(~' '&'a')))
if (putchar('w'%(~' '&'a')))
if (putchar('x'%(~' '&'a')))
if (putchar('y'%(~' '&'a')))
if (putchar('z'%(~' '&'a')))
if (putchar('{'%(~' '&'a')))
if (putchar('|'%(~' '&'a')))
if (putchar('}'%(~' '&'a')))
if (putchar('~'%(~' '&'a')))
if (putchar('~'%(~'!'&'a')))
if (putchar(~(~('~'%(~'!'&'a'))&~(~' ' & '!'))))
if (putchar(~'!'&'a'))
if (putchar(~' '&'a'))
if (putchar(~' '&'b'))
if (putchar(~' '&'c'))
if (putchar(~' '&'d'))
if (putchar(~' '&'e'))
if (putchar(~' '&'f'))
if (putchar(~' '&'g'))
if (putchar(~' '&'h'))
if (putchar(~' '&'i'))
if (putchar(~' '&'j'))
if (putchar(~' '&'k'))
if (putchar(~' '&'l'))
if (putchar(~' '&'m'))
if (putchar(~' '&'n'))
if (putchar(~' '&'o'))
if (putchar(~' '&'p'))
if (putchar(~' '&'q'))
if (putchar(~' '&'r'))
if (putchar(~' '&'s'))
if (putchar(~' '&'t'))
if (putchar(~' '&'u'))
if (putchar(~' '&'v'))
if (putchar(~' '&'w'))
if (putchar(~' '&'x'))
if (putchar(~' '&'y'))
if (putchar(~' '&'z'))
if (putchar(~' '&'{'))
if (putchar(~' '&'|'))
if (putchar(~' '&'}'))
if (putchar(~' '&'~'))
if (putchar(~(~(~' '&'~')&~(~' ' & '!'))))
if (putchar(~('!'%' ')&'a'))
if (printf("abcdefghijklmnopqrstuvwxyz{|}~}|{zyxwvutsrqponmlkjihgfedcba"))
if (putchar(~('!'%' ')&'a'))
if (putchar(~(~(~' '&'~')&~(~' ' & '!'))))
if (putchar(~' '&'~'))
if (putchar(~' '&'}'))
if (putchar(~' '&'|'))
if (putchar(~' '&'{'))
if (putchar(~' '&'z'))
if (putchar(~' '&'y'))
if (putchar(~' '&'x'))
if (putchar(~' '&'w'))
if (putchar(~' '&'v'))
if (putchar(~' '&'u'))
if (putchar(~' '&'t'))
if (putchar(~' '&'s'))
if (putchar(~' '&'r'))
if (putchar(~' '&'q'))
if (putchar(~' '&'p'))
if (putchar(~' '&'o'))
if (putchar(~' '&'n'))
if (putchar(~' '&'m'))
if (putchar(~' '&'l'))
if (putchar(~' '&'k'))
if (putchar(~' '&'j'))
if (putchar(~' '&'i'))
if (putchar(~' '&'h'))
if (putchar(~' '&'g'))
if (putchar(~' '&'f'))
if (putchar(~' '&'e'))
if (putchar(~' '&'d'))
if (putchar(~' '&'c'))
if (putchar(~' '&'b'))
if (putchar(~' '&'a'))
if (putchar(~'!'&'a'))
if (putchar(~(~('~'%(~'!'&'a'))&~(~' ' & '!'))))
if (putchar('~'%(~'!'&'a')))
if (putchar('~'%(~' '&'a')))
if (putchar('}'%(~' '&'a')))
if (putchar('|'%(~' '&'a')))
if (putchar('{'%(~' '&'a')))
if (putchar('z'%(~' '&'a')))
if (putchar('y'%(~' '&'a')))
if (putchar('x'%(~' '&'a')))
if (putchar('w'%(~' '&'a')))
if (putchar('v'%(~' '&'a')))
if (putchar('u'%(~' '&'a')))
if (putchar('t'%(~' '&'a')))
if (putchar('s'%(~' '&'a')))
if (putchar('r'%(~' '&'a')))
if (putchar('q'%(~' '&'a')))
if (putchar('p'%(~' '&'a')))
if (putchar('o'%(~' '&'a')))
if (putchar('n'%(~' '&'a')))
if (putchar('m'%(~' '&'a')))
if (putchar('l'%(~' '&'a')))
if (putchar('k'%(~' '&'a')))
if (putchar('j'%(~' '&'a')))
if (putchar('i'%(~' '&'a')))
if (printf("'&%%$#"))
if (putchar('"'))
if (printf("! "))
{}
}

```

The ascii subset is 32...41 and 97...126.

I am not sure whether newline characters are allowed in code; if not, just remove them.

# Answer
> 6 votes
# Whirl, N=2, 6486 bytes

Using only 2 characters, `01`.

```
[encoded data, 6486 characters]

```

Output :

```
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!

```

I think I can golf down more using loops, but coding with 0s and 1s was horrible, so I won't do it.

## Commented

```
00011000001111 // init math.val to O
0000100000100000100000100000100000100000100000100000100000100 // math.val to 32, mem to 32
110000 // set IO to print
0111001111000100000001111100000100 // print ascii(32), mem to 33
01001111000100000001111100000100 // print ascii(33), mem to 34
01001111000100000001111100000100 // print ascii(34), mem to 35
01001111000100000001111100000100 // print ascii(35), mem to 36
                                 // skipped
01001111000100000001111100000100 // print ascii(l23), mem to l24
01001111000100000001111100000100 // print ascii(l24), mem to l25
01001111000100000001111100000100 // print ascii(l25), mem to l26
0100 // print ascii(l26)
111100010000000100001111000001000100 // mem to l25, print ascii(l25)
111100010000000100001111000001000100 // mem to l24, print ascii(l24)
111100010000000100001111000001000100 // mem to l23, print ascii(l23)
                                     // skipped
111100010000000100001111000001000100 // mem to 34, print ascii(34)
111100010000000100001111000001000100 // mem to 33, print ascii(33)
111100010000000100001111000001000100 // mem to 32, print ascii(32)
0001100 // KTHXBAI

```

Note that there's `O` and `l` as `0` and `1`.

# Answer
> 5 votes
# C; N = 61 = 58 + 3

To compensate for using such a large subset, I golfed my code.

```
a;main(d){for(;d&&++a,d||--a;putchar(a+31),a-95||--d);}

```

The ASCII subset is 32...59 and 97...126.

It was a fun challenge to avoid the `=` character!

# Answer
> 4 votes
# Python 2.7 N=45=42+3

This uses `string.printable`, sorts and spits it out over `stdout`. I save a few characters by inserting the `.` in `stdout.write` by using `eval` and string formating using the `ord` values of characters I could use.

```
from string import printable
from sys import stdout
eval("map(stdout%swrite,sorted(printable,None,ord))"%chr(ord('+') + ord('z')-ord('w') ))
print ""
eval("map(stdout%swrite,reversed(sorted(printable,None,ord)))"%chr(ord('+') + ord('z')-ord('w') ))

```

### Out with the old - N=49=46+3

~~Unfortunately, while python includes the `string.printable` list, this isn't in ascii order, and there is no way to use it without a `*` or a `.`, so it takes less characters to do it manually.~~

Using the character range:

```
abcdefghijklmnopqrstuvwxyz{|}~ AND   !"#$%&'()*+,-.

print ''.join((chr(i)
  for i in range(
    len('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
    len('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
  )))
print ''.join((chr(i)
  for i in range(
    len('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
    len('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
    -len('x')
  )))

```

### The obvious version: N=63=60+3

This is the obvious version using the character range:

```
[\]^_`abcdefghijklmnopqrstuvwxyz{|}~   AND   !"#$%&'()*+,-./01234567 `:

print ''.join([chr(i) for i in range(0x20,0x7E)])
print ''.join(reversed([chr(i) for i in range(0x20,0x7E)]))

```

# Answer
> 3 votes
# Python 2.7 N=28+12+3=43

Using characters `cdefghijklmnopqrstuvwxyz{|}~` and then wrapping around to  `!"#$%&'()*+`

```
exec "print ''"
   + chr(ord('+') + len('xxx'))        # .
   + "join(chr(i) for i in r"
   + chr(ord('c') + ~len('x'))         # a
   + "nge(ord(' ')"                    # 32
   + chr(ord('+') + len('x'))          # ,
   + " ord('~') + len('x'))) + ''"     # 127
   + chr(ord('+') + len('xxx'))        # .
   + "join(chr(i) for i in r"
   + chr(ord('c') + ~len('x'))         # a
   + "nge(ord('~')"                    # 126
   + chr(ord('+') + len('x'))          # ,
   + " ord(' ') + ~len('')"            # 31
   + chr(ord('+') + len('x'))          # ,
   + " + ~len('')))"                   # -1

```

In order to avoid using `,.-` I had to use some tricks. I used `exec` so I can make the code into strings which allowed me to use `chr(ord('+') + len('xxx'))` for `.` and `chr(ord('+') + len('x'))` for `,`. Any place I needed a -1, I used ~0 in the form of `~len('')`. To avoid `a`, I used `chr(ord('c') + ~len('x'))` (99 - 2).

The string that gets composed has N=48, using characters `abcdefghijklmnopqrstuvwxyz{|}~` and then wrapping around to  `!"#$%&'()*+,-.`

```
print ''.join(chr(i) for i in range(ord(' '), ord('~') + len('x')))
    + ''.join(chr(i) for i in range(ord('~'), ord(' ') + ~len(''), + ~len('')))

```

Note that the newlines and comments are only for readability.

# Answer
> 2 votes
# Ruby - N=48

Let Ruby be Ruby and embrace the wrap-around penalty.
N=48 \<- 15 (' '-'.') + 30 ('a'-'~') + 3

```
eval "for c in ' '..'~' do putc c end #{('i'.ord-'.'.ord).chr} for c in ' '..'~' do putc ('~'.ord+' '.ord-c.ord).chr end"

```

or

```
eval "(' '..'~').each { |c| putc c } #{('i'.ord-'.'.ord).chr} (' '..'~').each { |c| putc ('~'.ord+' '.ord-c.ord).chr }"

```

Old:
N=72 {straight-line scoring} \<- 72 ('.'-'u') + invalid newlines

```
format = 67.chr
format << 42.chr
a = []
for i in 33..126 do a << i end
t = a.dup
for i in 33..126 do a << t.pop end
puts a.pack format

```

There's some flailing in here to avoid the 'v' in "reverse". I left it in because I'm fond of the pack("C\*") hack.

# Answer
> 2 votes
# Zsh, N = 22 + 2 + 3 = 27

```
print {~..!} {!..~}

```

Try it online!

`print` turns out to be the most forgiving way to output for this challenge; `echo` has a "c", and `<<<` ends up too far away too (not to mention brace expansions aren't expanded with it).

As for why I used `!` instead of :

```
print {~.. } { ..~}      # would save a point, but doesn't work
print {~..\ } {\ ..~}    # works, but costs 13 points compared to "!"
print {~..' '} {' '..~}  # works, but costs  6 points compared to "!"
print {~.." "} {" "..~}  # works, but costs  1 point  compared to "!"

```

Instead, we rely on `print` joining the arguments with spaces to get the middle space.

# Answer
> 1 votes
**x86\_64 Machine Code, Mach-O format**

**N = 2, 32768 chars (too large to fit msg limit)**

**Edit:** Pastebin is down, so you can find the full text at: http://www.ionoclast.com/random/golf.bin.txt

# Answer
> 1 votes
# Ruby, N = 27

Uses `$` through `>`.

```
$><<(''<<32<<33<<34<<35<<36<<37<<38<<39<<40<<41<<42<<43<<44<<45<<46<<47<<48<<49<<50<<51<<52<<53<<54<<55<<56<<57<<58<<59<<60<<61<<62<<63<<64<<65<<66<<67<<68<<69<<70<<71<<72<<73<<74<<75<<76<<77<<78<<79<<80<<81<<82<<83<<84<<85<<86<<87<<88<<89<<90<<91<<92<<93<<94<<95<<96<<97<<98<<99<<100<<101<<102<<103<<104<<105<<106<<107<<108<<109<<110<<111<<112<<113<<114<<115<<116<<117<<118<<119<<120<<121<<122<<123<<124<<125<<126<<126<<125<<124<<123<<122<<121<<120<<119<<118<<117<<116<<115<<114<<113<<112<<111<<110<<109<<108<<107<<106<<105<<104<<103<<102<<101<<100<<99<<98<<97<<96<<95<<94<<93<<92<<91<<90<<89<<88<<87<<86<<85<<84<<83<<82<<81<<80<<79<<78<<77<<76<<75<<74<<73<<72<<71<<70<<69<<68<<67<<66<<65<<64<<63<<62<<61<<60<<59<<58<<57<<56<<55<<54<<53<<52<<51<<50<<49<<48<<47<<46<<45<<44<<43<<42<<41<<40<<39<<38<<37<<36<<35<<34<<33<<32)

```

# Answer
> 1 votes
# Scala, N = 69

```
\u0028\u0027\u0020\u0027\u0074\u006f\u0027\u007e\u0027\u0029\u002b\u002b\u0028\u0027\u007e\u0027\u0074\u006f\u0027\u0020\u0027\u0029

```

Uses the characters `01246789\bdefu` (unicode escapes) as a fancy way of writing `(' 'to'~')++('~'to' ')map print`.

# Answer
> 0 votes
# Lenguage, N=1, 1051031305378170472802141990371710130229567839916356530545925757126045319904479746110699524004618985593156618424109188625672742261101447765479880468512170844090412908982576756544352839464930752275112743890775461636401594361137373794023488860005007435006520443129620535092091787646449862714370596024435599036073543700063989003712012285691090357581157986517772 bytes

```
                    ...1051031305378170472802141990371710130229567839916356530545925757126045319904479746110699524004618985593156618424109188625672742261101447765479880468512170844090412908982576756544352839464930752275112743890775461636401594361137373794023488860005007435006520443129620535092091787646449862714370596024435599036073543700063989003712012285691090357581157986517732 spaces omitted...
```

This gets converted to the brainf\*** program `++++[->++++++++<]>.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.` using the method described here, which outputs  `!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!` .

# Answer
> 0 votes
# Thunno `J`, n=25, 21 bytes

```
32+127:C0126+095:-CA+

```

Attempt This Online!

Uses `+` (43) to `C` (67)

#### Explanation

```
32           # Push 32
  +          # Add this to 0 (this is just so that we have
             # a separator between the numbers - usually
             # we use a space but that's too far away)
   127       # Push 127
      :      # Get the range between 32 and 127
       C     # Convert each to a character from a charcode
        0    # Push 0
         126 # Push 126
+            # Add them together (acts as a separator again)
 0           # Push 0
  95         # Push 95
    :        # Get the range between 0 and 95
     -       # Subtract each from 126
      C      # Convert each to a character from a charcode
       A+    # Concatenate the two lists
             # J flag joins into a single string
             # Implicit output

```

---
Tags: code-challenge, restricted-source, printable-ascii
---


title: Draw Parcly Taxel's cutie mark

text:
# Question
Title: Draw Parcly Taxel's cutie mark
I've been a fan of *My Little Pony: Friendship Is Magic* for a long time, and very early on I created a pony version of myself also called Parcly Taxel (warning: may be too cute to look at). The symbol below is her "cutie mark", which you will be drawing here:

## Construction

All key points of the cutie mark lie on a rotated hexagonal grid, which will be given coordinates such that (1,0) is 15 degrees counterclockwise from the \\$+x\\$-axis and (0,1) is likewise 75 degrees counterclockwise.

* One of the six "arms" of the galaxy is bounded by the following segments in order:
    + A cubic Bézier curve with control points (3,-2), (4,0), (5,4), (-2,12)
    + A straight line from (-2,12) to (3,9)
    + A cubic Bézier curve with control points (3,9), (7,3), (6,-1), (4,-3)
    + A straight line from (4,-3) to (3,-2)
* The other five arms are obtained by successive 60-degree rotations of the initial arm about the origin. Their fill alternates between RGB `#5A318E`/`(90,49,142)` (dark blue) and `#54A2E1`/`(84,162,225)` (light blue), with the initial arm getting `#5A318E`. They have no stroke.
* Layered above the arms is a regular hexagon centred on the origin and with one vertex at (5,1). It has no fill and is instead stroked with RGB colour `#576AB7`/`(87,106,183)` (medium blue), has stroke width 0.5 and has miter join. Parts of the arms should show inside the hexagon.

## Task

Draw Parcly Taxel's cutie mark, with the following stipulations:

* Your program must generate the image by itself and not download it from a website.
* The image can be saved to a file or piped raw to stdout in any common image file format, or it can be displayed in a window.
* The image must have (to best effort) the same orientation and aspect ratio as those implied by the construction. Raster images must be at least 400 pixels wide, and an error of 2 pixels/1% is allowed.
* If your language does not support arbitrary RGB colours you may use any colours reasonably recognisable as light, medium and dark blue.

This is ; fewest bytes wins.

I made this challenge to celebrate reaching 100,000 reputation on the Mathematics Stack Exchange, which I achieved on 27 February 2023.

# Answer
> 8 votes
## SVG (HTML5), ~~361~~ ~~357~~ 337 bytes

```
<svg viewBox=-25,-25,50,50><g fill=#54A2E1><g id=g><path id=a d=M.4,5.3C5.7,5.7,14.8,5,20.4,-9L21.6,-.4C15.7,8.3,6.6,9,-.1,7.2 /><use href=#a transform=rotate(120) /><use href=#a transform=rotate(240)></g><use href=#g transform=rotate(60) fill=#5A318E /><path d=M1.2,-11.1l9,6.6L9,6.6L-1.2,11.1l-9,-6.6L-9,-6.6Z fill=none stroke=#576AB7>
```

Edit: Saved ~~4~~* 24 bytes thanks to @ccprog. (I would have done it myself but the old version used a lot of integers and I was expecting to have to waste many bytes on the accuracy, but it turns out that e.g. √2(7-4√3) is amazingly close to 5!)

\*crossed out 4 is still regular 4

# Answer
> 7 votes
# PaperScript, ~~358~~ ~~355~~ 352 bytes

```
H=(a,b)=>new Point(a+b/2,-b*.75**.5)
for(i=0;6>i++;){p=new Path(H(4,-3))
p.C=p.cubicCurveTo
p.C(H(6,-1),H(7,3),H(3,9))
p.lineTo(H(-2,12))
p.C(H(5,4),H(4,0),H(3,-2))
p.closed=1
p.fillColor=i%2?"#54A2E1":"#5A318E"
p.pivot=0
p.rotation=60*i-15}v=H(5,1)
h=Path.RegularPolygon([0,0],6,v.length)
h.strokeColor="#576AB7"
h.strokeWidth=.5
h.rotation=v.angle+15

```

You can try it here. Paste in the code, and either add the following lines at the end:

```
view.center = [0,0]
view.zoom = 10

```

or use the magnifying glass tool to zoom in on the drawing (which will be partially visible in the top left corner of the canvas).

### Ungolfed and commented

```
// Convert hex coordinates (a, b) to Cartesian coordinates (x, y)
// (without the extra 15-degree rotation, which we will apply later)
function hexPoint(a, b) {
    // a and b represent the magnitudes of two vectors whose
    // sum is the point we want. The a vector points to the right
    // (angle = 0 degrees) and the b vector points up and right
    // (angle = -60 degrees, due to positive y being down in
    // this coordinate system).
    // Thus, x is a * cos(0) + b * cos(-60), which simplifies to:
    var x = a + b / 2;
    // and y is a * sin(0) + b * sin(-60):
    var y = b * -Math.sqrt(3 / 4);
    return new Point(x, y);
}

// Draw the six arms
// We draw each arm using the reference points given, then set its
// fill color and rotate it according to the loop index
for (var i = 0; i < 6; i++) {
    // Start at (4, -3)
    var arm = new Path(hexPoint(4, -3));
    // Draw a cubic Bézier curve from there to (3, 9), with handles
    // at (6, -1) and (7, 3)
    arm.cubicCurveTo(hexPoint(6, -1), hexPoint(7, 3), hexPoint(3, 9));
    // Draw a line from there to (-2, 12)
    arm.lineTo(hexPoint(-2, 12));
    // Draw a cubic Bézier curve from there to (3, -2), with handles
    // at (5, 4) and (4, 0)
    arm.cubicCurveTo(hexPoint(5, 4), hexPoint(4, 0), hexPoint(3, -2));
    // Close the path
    arm.closed = true;
    // Fill with dark blue if i is even, light blue if i is odd
    arm.fillColor = i % 2 ? "#54A2E1" : "#5A318E";
    // Set the pivot point to the origin
    arm.pivot = new Point(0, 0);
    // Pivot the arm around that point 15 degrees counterclockwise
    // and 60 * i degrees clockwise
    arm.rotation = -15 + 60 * i;
}

// Draw the hexagon
// We know one of its vertices is at (5, 1), so we'll use that to
// calculate the right numbers for Paper.js's polygon-drawing
// function and a subsequent rotation
var vertex = hexPoint(5, 1);
// Draw a polygon:
hexagon = Path.RegularPolygon({
    // Centered at the origin
    center: new Point(0, 0),
    // With six sides
    sides: 6,
    // With radius equal to the length of a vector from the origin
    // to the vertex
    radius: vertex.length,
    // Medium blue
    strokeColor: "#576AB7",
    // With 0.5 stroke width
    strokeWidth: 0.5,
    // With these rotations:
    //  30 degrees clockwise because the default orientation is
    //   pointy-topped but we want flat-topped
    //  15 degrees counterclockwise because of the rotation of
    //   the whole figure
    //  An angle equal to the angle a vector from the origin to
    //   the previously calculated vertex makes with the x-axis
    rotation: 30 - 15 + vertex.angle,
    // With miter join style (default, don't need to specify)
});

// Put the origin in the center of the view and zoom in so the
// figure is more visible
view.center = new Point(0, 0);
view.zoom = 10;

```

# Answer
> 7 votes
# JavaScript (ES6), 273 bytes

*Thanks to @Shaggy for suggesting to switch from HTML+JS to JS and saving 2 bytes in the new version*

Generates a SVG similar to this one from Parcly Taxel.

```
f=(s=`<svg viewBox="-22 -23 44 4${a=6}">`)=>a--?f(s+(p='<path fill=')+`#5${a&1?'a318e':'4a2e1'} d="M20.3-9C14.8 5 5.8 5.6.4 5.3L-.1 7.2C6.5 9 15.6 8.4 21.6-.4" transform="rotate(${a*60})"/>`):s+p+`none stroke=#576ab7 d="M-10.2 4.5-9-6.6 1.2-11.1 10.2-4.5 9 6.6-1.2 11.1Z">`

```

Try it online!

### Graphical output

```
f=(s=`<svg viewBox="-22 -23 44 4${a=6}">`)=>a--?f(s+(p='<path fill=')+`#5${a&1?'a318e':'4a2e1'} d="M20.3-9C14.8 5 5.8 5.6.4 5.3L-.1 7.2C6.5 9 15.6 8.4 21.6-.4" transform="rotate(${a*60})"/>`):s+p+`none stroke=#576ab7 d="M-10.2 4.5-9-6.6 1.2-11.1 10.2-4.5 9 6.6-1.2 11.1Z">`

document.write(f())
```

# Answer
> 3 votes
## SVG: 737 bytes

```
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-22 -23 44 46"><defs><path id="s" d="M6 28C4 24 2 16 16 0L6 6C-2 18 0 26 4 30z"/></defs><g transform="rotate(-15)"><use transform="matrix(1,0,.5,-.87,-24,21)" href="#s" fill="#54A2E1"/><use transform="rotate(60) matrix(1,0,.5,-.87,-24,21)" href="#s" fill="#5A318E"/><use transform="rotate(120)matrix(1,0,.5,-.87,-24,21)" href="#s" fill="#54A2E1"/><use transform="rotate(180)matrix(1,0,.5,-.87,-24,21)" href="#s" fill="#5A318E"/><use transform="rotate(240)matrix(1,0,.5,-.87,-24,21)" href="#s" fill="#54A2E1"/><use transform="rotate(300)matrix(1,0,.5,-.87,-24,21)" href="#s" fill="#5A318E"/><path style="fill:none;stroke:#576AB7" d="M-11 1.7-7-8.7l11-1.7 7 8.7L7 8.7l-11 1.7z4"/></g></svg>

```

Using Parcly Taxel's SVG code here we can get a diff (mine in full color, original in red behind):

I could get it closer with a better transform matrix but that would require a larger file size.

# Answer
> 2 votes
## Pug (HTML), ~~266~~ 267 bytes

```
- i=0
svg(viewBox='-25,-25,50,50')
 while i<6
  path(d='M3-2C4,0,5,4-2,12L3,9C7,3,6-1,4-3' fill=`#5${i&1?'4a2e1':'a318e'}`transform=`rotate(${60*i++})matrix(1.93-.52.52-1.93,0,0)`)
 path(d='M1.2-11.1l9,6.6L9,6.5-1.2,11.1l-9-6.6L-9-6.5Z' fill='none' stroke='#576AB7')

```

Try it online

The coordinate system transformation can be written as a matrix

$$\begin{matrix}\\ 1 & tan(15°) & 0\\ -tan(15°) & -1 & 0\\ 0 & 0 & 1\\ \end{matrix}$$

For a unit length of 2, (so the stroke width of the hexagon is 1), this has to be scaled with \\$\frac{2}{cos(15°)}\\$.

The path data remain in their original coordinate system as defined for the arms, but to ensure the constant stroke width of the hexagon, pretransformed path data are used.

# Answer
> 0 votes
# JShell 17: 490 488 + 6 bytes

Requires the `JAVASE` arg to be passed to JShell. I'm unsure how that's scored, hence the "+6" in the title. Shows the image in a window ~~that might be hard to find at first~~.

```
new Frame(){public void paint(Graphics h){var g=(Graphics2D)h;g.rotate(-Math.PI/12);var p=new GeneralPath();for(var i=0;i<6;i++,g.rotate(Math.PI/3,169,304),g.setColor(new Color(5910926-i%2*364205)),p.moveTo(249,96),p.curveTo(309,235,249,304,209,338),p.lineTo(219,355),p.curveTo(279,321,339,252,319,148),p.closePath(),g.fill(p));int[]a={279,238,129,59,99,209},b={287,390,407,320,217,200};g.setColor(new Color(5728951));g.setStroke(new BasicStroke(10));g.draw(new Polygon(a,b,6));}}.show();

```

A surprising topic for a code golf challenge, nice!
What isn't surprising however is the not very competitive score... but as long as my Java answer isn't twice as long as its competitors, I'm happy with it.

This entry uses precalculated values whereever possible. I lose some precision doing this, but as I'm outputting a raster image I still get a fairly accurate result as this overlayed image shows:

In the end, I was able to gain two bytes by reducing the image size from 900x900 to 450x450, making the accuracy loss more noticeable. Here is the original post in case the error is too big:

```
new Frame(){public void paint(Graphics h){var g=(Graphics2D)h;g.rotate(-Math.PI/12);var p=new GeneralPath();for(var i=0;i<6;i++,g.setColor(new Color(5910926-i%2*364205)),p.moveTo(465,160),p.curveTo(585,437,465,575,385,644),p.lineTo(405,678),p.curveTo(525,609,645,472,605,264),p.closePath(),g.fill(p),g.rotate(Math.PI/3,305,575));int[]a={525,444,225,85,166,385},b={542,748,782,608,402,368};g.setColor(new Color(5728951));g.setStroke(new BasicStroke(20));g.draw(new Polygon(a,b,6));}}.show();

```

---
Tags: code-golf, graphical-output
---


title: Largest Binary Area

text:
# Question
Title: Largest Binary Area
Take the sequence of all natural numbers in binary, `(1, 10, 11, ..)` then write them vertically beside each-other like this (least significant bit on top; 0s have been replaced with spaces):

```
1 1 1 1 1 1 1 1 1
 11  11  11  11
   1111    1111
       11111111
               11

```

Notice there are areas of connected 1s in the binary representation of the number.

Your task is, for a given `n`, calculate the biggest continuous area in the binary representation of all numbers less than `n`. If you start with n=1 and consider all numbers less than or equal to n, the sequence starts like this:

```
(1, 1, 3, 3, 3, 4, 7, 7, 7, 7, 7, 7, 8, 11, 15, 15, 15...)

```

Areas are joined if they connect horizontally or vertically, diagonals don't count.

rules apply: you can choose to consider either all numbers *strictly less than* N or those *less than or equal to* N, and either 0 or 1. This is , shortest answer wins.

# Answer
> 9 votes
# JavaScript (V8), 67 bytes

Prints the sequence infinitely.

```
for(m=n=0;g=k=>k?!(k&k+1)+g(k>>1):s;print(m=m>s?m:s))s=n&++n?g(n):1

```

Try it online!

### How?

This is based on the observation that the biggest local area is always those of the pattern formed by the leading 1's (in red below).

If the area of the leading pattern is \\$N\\$, any non-leading pattern may at best reach an area of \\$N-1\\$ (like the green one in figure 2).

(Figure 1 is for \\$n=8\\$ to \\$n=15\\$. Figure 2 is for \\$n=16\\$ to \\$n=23\\$.)

### Commented

```
for(              // infinite loop:
  m =             //   m = current maximum
  n = 0;          //   n = counter
  g = k =>        //   g is a helper recursive function taking k
                  //   and returning the sum of s and the number
                  //   of leading 1's in k
    k ?           //   if k is not 0:
      !(          //     increment the final result if ...
        k & k + 1 //     ... k and k+1 have no bits in common
      ) +         //     (i.e. k+1 is a power of 2)
      g(k >> 1)   //     do a recursive call with floor(k / 2)
    :             //   else:
      s;          //     stop and return s
  print(          //   after each iteration, print ...
    m = m > s ? m //   ... the maximum of m and s
              : s //   (and update m accordingly)
  )               //
)                 //
  s =             //   s is the area of the pattern of leading 1's
    n & ++n ?     //   increment n; if n is not a power of 2:
      g(n)        //     update s to g(n)
    :             //   else:
      1           //     reset s to 1

```

# Answer
> 7 votes
# MATL, ~~14~~ 13 bytes

*1 byte saved thanks to @Suever*

```
:B4&1ZIXz5#XM

```

Inputs `n` and outputs the `n`-th term of the sequence, using the "less or equal" definition.

Try it MATL online!

### Explanation

```
:       % Implicit input: n. Range [1 2 ... n]
B       % Convert to binary. Gives an n-row matrix
4&1ZI   % Label connected components, using 4-neighbourhood. This labels each
        % connected component of cells equal to 1 with an integer, starting at 1
Xz      % Nonzeros. Removes zeros and reshapes into a column vector
5#XM    % Second output of 'mode' function: gives the number of times that the
        % mode occurs. Implicit display

```

# Answer
> 2 votes
# Python, ~~95 93 92~~ 88 bytes

```
m=n=0
while g:=lambda k:k and(k&k+1<1)+g(k>>1):print(m:=max(m,s:=n&(n:=n+1)<1or g(n)+s))

```

Attempt This Online!

Outputs `True` instead of `1`. +2 bytes to fix this

Port of Arnauld's JS answer.

*-2 thanks to @Arnauld*
*-4 thanks to @97.100.97.109*

# Answer
> 2 votes
# Python3, 333 bytes:

```
E=enumerate
def f(n):
 t=[*map(bin,range(1,n))]
 k=[i[2:][::-1]+'0'*(max(map(len,t))-len(i))for i in t]
 q,l=[(x,y)for x,r in E(k)for y,u in E(r)if'1'==u],[]
 while q:
  Q,s=[q.pop(0)],1
  while Q:
   x,y=Q.pop(0)
   for X,Y in[(0,1),(0,-1),(1,0),(-1,0)]:
    C=(x+X,y+Y)
    if C in q:Q+=[C];q.remove(C);s+=1
  l+=[s]
 return max(l)

```

Try it online!

# Answer
> 2 votes
# Charcoal, 28 bytes

```
ＦＮ«≔⁺∧＆ι⊕ιθＬ§⪪⍘⊕ι²0⁰θ⊞υθ⟦Ｉ⌈υ

```

Try it online! Link is to verbose version of code. Outputs the first `n` terms. Explanation:

```
ＦＮ«

```

Repeat `n` times.

```
≔⁺∧＆ι⊕ιθＬ§⪪⍘⊕ι²0⁰θ

```

If the effective 1-based index is a power of 2, then start the new area from 1, otherwise add the number of leading 1s to it.

```
⊞υθ

```

Save the size of the latest area.

```
⟦Ｉ⌈υ

```

Output the size of the largest area.

I did find some relevant sequences in the OEIS:

* A000225 is the list of indices where the size of the largest contiguous area equals the index.
* A090996 is the number of leading 1s.
* A267604 appears to be list of indices where the new area overtakes the old area in size.

Unfortunately I was unable to use any of these sequences to reduce my byte count.

# Answer
> 2 votes
# Jelly,  ~~12~~  11 bytes

```
B«\)LÐṀFS)Ṁ

```

A monadic Link that accepts \\$n\\$ and yields the largest binary area when arranging the numbers \\$1\\$ to \\$n\\$ inclusive.

**Try it online!**

### How?

```
B«\)LÐṀFS)Ṁ - Link: positive integer, n
         )  - for each (i in [1..n]):
   )        -   for each (j in [1..i]):
B           -     convert (j) to binary
  \         -     cumulative reduce by:
 «          -       minimum (i.e. zero any bits after the first 0)
     ÐṀ     -   keep those maximal under:
    L       -     length (e.g. j = 27 -> [zeroed(binary(16))..zeroed(binary(27))])
       F    -   flatten
        S   -   sum
          Ṁ - maximum

```

# Answer
> 1 votes
# Python 3.8, 85 bytes

```
lambda n:max((j:=2**len(bin(n))>>3)-1,sum(bin(i*2)[2:].find('0')for i in range(j,n)))

```

An anonymous function that accepts a positive integer, `n`, and returns the largest binary area formed using the numbers less than `n`.

**Try it online!**

---
Tags: code-golf, number, sequence, binary, binary-matrix
---


title: Pad a jagged array to be square

text:
# Question
Title: Pad a jagged array to be square
Given a 2-dimensional jagged array and a fill value, pad the array in both dimensions with the fill value to ensure that it is square and not jagged (i.e., all rows are the same length, and that length is the same as the number of rows).

The fill values should always be added to the "edges", which may be the start or the end, but not in the middle.

For example, with the fill value `8`, this array:

```
[[1, 5, 3],
 [4, 5],
 [1, 2, 2, 5]]

```

could become:

```
[[1, 5, 3, 8],
 [4, 5, 8, 8],
 [1, 2, 2, 5],
 [8, 8, 8, 8]]

```

Here is another valid output:

```
[[8, 8, 8, 8],
 [8, 1, 5, 3],
 [8, 4, 5, 8],
 [1, 2, 2, 5]]

```

However, the padding should be minimal: the size of the output square should be equal to the maximum of the length of the rows and the number of rows. For example, this is not a valid output for the input above:

```
[[1, 5, 3, 8, 8],
 [4, 5, 8, 8, 8],
 [1, 2, 2, 5, 8],
 [8, 8, 8, 8, 8],
 [8, 8, 8, 8, 8]]

```

## More test cases

All using fill value `0` for simplicity.

```
Input:
[]
Output:
[]

```

```
Input:
[[],
 []]
Output:
[[0, 0],
 [0, 0]]

```

```
Input:
[[5]]
Output:
[[5]]

```

```
Input:
[[0, 0],
 [0],
 [0, 0, 0]]
Output:
[[0, 0, 0],
 [0, 0, 0],
 [0, 0, 0]]

```

```
Input:
[[1, 2, 3, 4]]

Output:
[[1, 2, 3, 4],
 [0, 0, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 0]]

```

```
Input:
[[1],
 [2],
 [3],
 [4, 5]]
Output:
[[1, 0, 0, 0],
 [2, 0, 0, 0],
 [3, 0, 0, 0],
 [4, 5, 0, 0]]

```

## Rules

* The array's elements and the fill value can be of whatever type or set of values you like, as long as there are at least two distinct possibilities. For example, you could use characters, where the array is a multi-line string (where each line is a row), or you could restrict the values to single digits...
* Standard loopholes are forbidden
* Standard I/O rules apply
* This is , so the shortest code in bytes wins

# Answer
> 9 votes
# Haskell, 67 bytes

```
m%v|let l?x=take(maximum$length<$>(1<$m):m)$l++repeat x=(?v)<$>m?[]

```

Try it online!

# Answer
> 6 votes
# , ~~80~~ ~~90~~ ~~93~~ 88 bytes

*Edit: -5 bytes thanks to Kirill L., but only after +10 bytes to fix bug, and +3 more bytes after belatedly realising that the fill-value should be given as input...*

```
function(l,f,m=matrix(f,d<-max(0,seq(l),lengths(l)),d)){for(i in l)m[F<-F+1,seq(i)]=i;m}

```

Try it online!

# Answer
> 6 votes
# , 25 bytes

```
4 :'y([{.!.x&>{.)~>./$>y'

```

Try it online!

*Note: -3 off TIO for `f=.`*

Note that in J ragged arrays must be boxed.

This was surprisingly hard considering that J auto fills ragged arrays by default. Unfortunately, the default behavior is not quite enough for what's needed in this challenge.

## how

We take the fill as the left arg `x` and the input arrays as the right arg `y`, and use an explicit (rather than tacit) verb because the fit conjunction `!.` required to specify fill requires a value or named variable.

* `>./$>y` \- The max `>./` of the dimensions `$` of the opened input `>y`. We'll use this as the left argument of the main verb.
* `([ {.!.x&> {.)` The main verb, consisting of a fork whose right tine `{.` expands the boxed input to the required dimension by filling it with blank boxes. This handles what will ultimately become the "vertical expansion".
* `{.!.x&>` For each box `&>` (the original input, plus the empty expansions produced in the previous step), take `{.` the required length, filling missing items with the specified fill `!.x`. This handles the "horizontal expansion".

# Answer
> 6 votes
# K (ngn/k), ~~21~~ 19 bytes

```
{y^x .!'2#|/#'x,,x}

```

Try it online!

* `|/#'x,,x` get the size of the output (i.e. the maximum of the count of each row, and of the number of rows)
* `!'2#` build a list of two copies of 0..size (e.g. `(0 1 2 3;0 1 2 3)`)
* `x .` dot-apply into the input (out of bound accesses result in `0N`s)
* `y^` replace nulls with the fill number

# Answer
> 5 votes
# JavaScript (ES6), 92 bytes

Expects `(array)(value)`, where `array` contains positive integers (or any other truthy values).

```
a=>v=>[a,...a].sort((a,b)=>b.length-a.length)[0].map((_,y,A)=>A.map((_,x)=>(a[y]||0)[x]||v))

```

Try it online!

### Commented

```
a =>                  // a[] = jagged array
v =>                  // v = fill value
[a, ...a]             // build an array consisting of the jagged array itself
                      // followed by each of its rows
.sort((a, b) =>       // sort this array ...
  b.length - a.length //   ... from longest to shortest entry
)[0]                  // and keep the longest one
.map((_, y, A) =>     // for each row at position y in this array A[]:
  A.map((_, x) =>     //   for each entry at position x in A[]:
    (a[y] || 0)[x]    //     attempt to get the value at (x, y) in a[]
    || v              //     if it fails, use the fill value instead
  )                   //   end of inner map()
)                     // end of outer map()

```

# Answer
> 5 votes
# JQ, 49 bytes

Takes input as an array of `[array, fill-element]`, where the array can hold any non-null type.

```
.[1]as$a|.[0]|transpose|transpose|map(map(.//$a))
EXPLANATION:
.[1]as$a|  # input array's second argument is in variable a
         .[0]|  # the first argument
              transpose|  # transposed, automatically placing null as a fill element
                        transpose|  # back to normal
                                  map(      # for each row
                                      map(  # for each element
                                          .//$a  # if it's null, the fill element, else it.
# // is like or in other languages, . means "it" or "it unchanged"

```

https://jqplay.org/s/8ADEt9WJGL

# Answer
> 4 votes
# APL (Dyalog Extended), 26 bytes (SBCS)

Anonymous infix lambda, taking fill as left argument and array as right argument.

```
{g←1⌷∘↑↑⍮∘⍉↑⋄⍺@(⍸~g=⍨⍵)g⍵}

```

Try it online!

`{``}` dfn; left argument (fill) is , right argument (array) is

`g←` define `g` as a tacit function:

`1⌷∘` the first layer of the 3D array that consist of

the 3D array consisting of the following two layers, padded with 0s:

`↑⍮∘⍉` the 2D array consisting of the given rows, padded with 0s, and the transposed…

2D array consisting of the given rows, padded with 0s

then:

`⍺@(``)` place fills **at** the indices given by:

the **ɩ**ndices where…

`~` there are zeros (lit. NOT)…

`g` in the fully padded version of…

`=⍨` the array identical to the given one, but with all elements made into 1s (lit. self-equality)

`g⍵` in the fully padded given array

# Answer
> 4 votes
# APL(Dyalog Unicode), ~~47 37~~ 32 bytes SBCS

```
{⍺@((,⍳x)~⍸↑=⍨⍵)⊢(x←2/⌈/⍴↑⍵)↑↑⍵}

```

Try it on APLgolf!

A dfn submission which takes fill element on the left, and ragged array on the right.

It calculates the indices of the existing elements and replaces everything else with the fill element.

-10, borrowing an idea from Adám's answer.

-5 from user.

# Answer
> 4 votes
# Functional Bash*, 167 161 147 bytes

* This is bash with the additional constraint that you can't mutate variables.

-14 bytes thanks to pxeger

```
m=`sort -n <(awk '{print NF}' $1) <(wc -l<$1)|tail -1`
s=`seq $m`
paste -d\  $1 <(printf "`printf "$2 %.s" $s`\n%.s" $s)|sed s/^\ //|cut -d\  -f-$m

```

Try it online!

The two arguments are:

* `$1`: file name containing lines of input
* `$2`: The fill character

The basic approach is to get the side length of the square (stored in `m`) and then create an `m` x `m` file of the fill, `paste` it with the original file, and take `m` fields from each line.

Would love to know if there's a terser approach.

# Answer
> 3 votes
# 05AB1E, ~~18~~ ~~17~~ 8 bytes

```
2FDªIζ€¨

```

-9 bytes by porting *@JonathanAllan*'s Jelly answer, so make sure to upvote him as well!

Try it online or verify all test cases.

**Previous 17 bytes answer:**

```
Dª€gà©nи®ô¹ì²ζø®∍

```

Try it online or verify all test cases.

**Explanation:**

```
2F                 # Loop 2 times:
  D                #  Duplicate the current matrix
                   #  (which will be the implicit input-matrix in the first iteration)
   ª               #  Append the matrix to itself
     ζ             #  Zip/transpose; swapping rows/columns,
    I              #  using the second input-character as filler
      €¨           #  And then remove the last item of each row
                   # (after the loop, the resulting matrix is output implicitly)

D                  # Duplicate the first (implicit) input-matrix
 ª                 # Append the matrix to itself
  €                # Map over each inner list:
   g               #  Pop and push its length
    à              # Pop and push the maximum
                   # (we now have the dimension of the output-square, which is either
                   #  equal to the amount of rows or amount of columns, whichever of
                   #  the two is larger)
     ©             # Store this maximum in variable `®` (without popping)
      n            # Square it
       и           # Repeat the second (implicit) input that amount of times as list
        ®ô         # Split it into parts of size `®`
          ¹ì       # Prepend the first input-matrix at the front
             ζ     # Zip/transpose; swapping rows/columns,
            ²      # using the second input-character as filler
              ø    # And then zip/transpose the rows/columns back
               ®∍  # Shorten the matrix to the first `®` amount of rows
                   # (after which the resulting matrix is output implicitly)

```

# Answer
> 3 votes
# Charcoal, 27 bytes

```
≔⌈⊞ＯＥηＬιＬηζＩＥ…⁺ηＥζυζ…⁺ιＥζθζ

```

Try it online! Takes the fill as first input and the jagged array as second input, but they can be trivially reversed if necessary. Outputs using Charcoal's default array format, which is each element on a separate line with rows double-spaced from each other. Explanation:

```
≔⌈⊞ＯＥηＬιＬηζ

```

Take the length of each element of the jagged array, tack on the length of the array itself, and then take the maximum of the result.

```
ＩＥ…⁺ηＥζυζ…⁺ιＥζθζ

```

Concatenate an array of empty arrays to the jagged array, then chop to the desired length. For each element of that array, concatenate an array of the fill value, then chop to the desired length. Print the result.

# Answer
> 3 votes
# Jelly, 8 bytes

```
ṭ`zṖ€ɗ⁺⁹

```

A dyadic Link accepting a, possibly jagged, two-dimensional array on the left and a fill value on the right which yields a square array which is filled rightwards and downwards with the fill value.

**Try it online!** (Footer added to format the resulting array, so that one can see the empty case work.)

### How?

```
ṭ`zṖ€ɗ⁺⁹ - Link: array, A; filler, F
       ⁹ - use the right argument, F, as the right argument of:
           (seems to be required for the ⁺, below)
      ⁺  -   repeat this link twice:
     ɗ   -     last three links as a dyad - f(current A, F):
  `      -       use left (A) as both arguments of:
 ṭ       -         tack - e.g. [[1],[2,3]] -> [[1],[2,3],[[1],[2,3]]]
                   (only thing that matters is that the tacked list has the length of A)
   z      -      transpose with filler (F) -> rectangular array right-filled.
    Ṗ€    -      pop an element off of each (removing the tacked lists)

```

# Answer
> 3 votes
# Python 2, 75 bytes

```
def f(M,v):n=max(map(len,M+[M]));print[(r+[v]*n)[:n]for r in(M+[[]]*n)[:n]]

```

Try it online!

# Answer
> 2 votes
# Charcoal, ~~15~~ 14 bytes

```
ＵＯ⌈⊞ＯＥθＬιＬθηＰθ

```

Matrix-input as a list of string-rows; filler-character as string input; and output as a printed multi-line string, which is allowed based on the first rule.

Try it online (verbose) or try it online (pure).

**Explanation:**

Determine the length of each row, the amount of rows, and then only leave the maximum of those combined:

```
Maximum(PushOperator(Map(q, Length(i)), Length(q)))
⌈⊞ＯＥθＬιＬθ

```

Draw a square of that size, using the second input-character as filler:

```
Oblong(..., h)
ＵＯ...η

```

Then print the first input on top of that to finish the intended result:

```
Multiprint(q)
Ｐθ

```

# Answer
> 2 votes
# Scala, 75 bytes

```
a=>p=>{val m=(a.map(_.size):+a.size).max
a.padTo(m,Seq())map(_.padTo(m,p))}

```

Try it online!

# Scala, 108 bytes

```
a=>p=>{val m=a.map(_.size)./:(a.size)(_ max _)
Seq.tabulate(m,m)((i,j)=>scala.util.Try(a(i)(j))getOrElse p)}

```

Try it online!

# Answer
> 2 votes
# Zsh, ~~91~~ 83 bytes

```
wc<I -lL|read l w
repeat w-l
echo>>I
while read i
do<<<${(pr/l>w?l:w//$1/)i}
done<I

```

Try it online!

Works character-wise, taking input from a file `I` and the first command-line argument.

This was going to be a suggestion to Jonah's Bash answer, but it became sufficiently different that I thought I'd post it separately.

* `wc -lL` \- output the number of lines and the maximum line length
* `<I` \- from the file `I`
* `|read l w` \- and store those values in the variables `l` and `w` respectively
* `repeat w-l` \- repeat \[the difference between `w` and `l`\] times:
    + `echo` \- print a blank line
    + `>>I` \- append that to the file `I`
    + this adds extra blank rows if needed; because if `w-l` is negative, the `repeat` won't execute at all
* `while read i` `do` `done<I` \- for each line in `I`:
    + `${i}` \- take that line, and
    + `(p)` \- substituting in the values of `m` and `1`,
    + `(r/l>w?l:w//$1/)` \- pad on the right using the character `$1` to the length `l>w?l:w`
        - `l>w?l:w` is the maximum line length and number of lines.
    + `<<<` \- and print that line

# Answer
> 2 votes
# Lua, ~~205~~ 187 bytes

```
load("t=".. ....."c=#t for i=1,c do c=math.max(c,#t[i])end p=io.write p'{'for i=1,c do for j=1,c do _=j==1 and p'{'p(t[i]and t[i][j]or 0)p(j==c and'}'or',')end _=i~=c and p','end p'}'")()

```

Try it online!

### Human readable code:

```
load(
  "t=".. .....
  "c=#t
   for i=1,c do
     c=math.max(c,#t[i])
   end
   p=io.write
   p'{'
   for i=1,c do
     for j=1,c do
       _=j==1 and p'{'
       p(t[i]and t[i][j]or 0)
       p(j==c and'}'or',')
     end
     _=i~=c and p','
   end
   p'}'
  ")
()

```

# Answer
> 2 votes
# Vyxal, ~~33 32 29~~ 10 bytes

```
2(:wJ⁰ÞṪvṪ

```

Try it Online!

Thanks to lyxal for -23 bytes.

# Answer
> 1 votes
# Canvas, 16 bytes

```
⁸）⁸∔０；｛ＬＭ｝⁷；：＊⁸ｎ

```

Try it here!

Takes an array of strings and a filler string as input.

# Answer
> 1 votes
# Python 3, 83 bytes

```
def f(l,v):x=max(map(len,l+[l]));return[a+[v]*(x-len(a))for a in l+[[]]*(x-len(l))]

```

Try it online!

# Answer
> 1 votes
# Julia, 82 bytes

```
f(a,b,L=max(length.([a;[a]])...),B=fill(b,L))=[(x->[x;B][1:L]).(a);fill(B,L)][1:L]

```

Try it online!

# Answer
> 1 votes
# Husk, ~~13~~ ~~14~~ ~~12~~ 14 bytes

*Edit: +1 byte to fix bug, then -2 bytes using a different approach, but then +2 bytes after realising we need to provide the fill-value as an argument*

```
₁₁²¹
T⁰ż+³RøLT

```

Try it online!

**How?**

```
    ₁₁          # apply helper function ₁ twice
                # helper function:
    T0          # transpose, padding with zeros,
      ż+¹       # input list zipped by element-wise concatenation with
         Rø     # a list of empty lists,
           LT   # as long as the longest list in the input list

```

---

Note after reading the other answers: I realised that a port of Jonathan Allan's approach is 1 byte shorter at ~~11~~ 13 bytes...

# Answer
> 1 votes
# C (gcc) with `-m32`, ~~173~~ 163 bytes

Thanks to ceilingcat for -10.

Takes an `NULL`-terminated array of strings and fill character, and returns a `NULL`-terminated array of padded strings with number of rows equal to the string length.

The function scans each string to find the longest length, then creates a destination array of the largest of the row count and maximum string length, plus 1. For each row, a string containing the fill character is allocated and generated, with the original string contents (minus the trailing `NUL`) then copied over the new string. The generated array is then returned to the caller.

```
*b,r,c,l;f(s,f)int*s;{for(r=c=0;s[r];)c=fmax(strlen(s[r++]),c);for(c=r=r>c?r:c,l=b=calloc(c+1,4);r--;*s?*stpcpy(*b,*s++)=f:0,b++)memset(*b=calloc(c+1,1),f,c);s=l;}

```

Try it online!

# Answer
> 1 votes
# Japt, 14 bytes

Takes an array of strings plus a single string as input, outputs an array of strings.

I spent five bytes finding the length of the longest string in the input, I would expect that to be somewhat crunchable.

```
úV ÕúVUñÊo Ê y
ú              // Right-pad every item in the first input to the length of the longest one
 V             // using the second input.
   Õ           // Transpose the rows with the columns,
    ú          // then right-pad every item again as above, except this time
           Ê   // pad to the length
       ñÊo     // of the longest item (sort by length, get the last item)
      U        // in the first input
     V         // using the second input as padding.
             y // Finally, transpose back and implicitly output the result.

```

Try it out here.

# Answer
> 1 votes
# APL, ~~34~~ 30 bytes

```
{M↑M↑¨(,∘S¨⍵),M/¨S←⍺⍴⍨M←⌈/⍴↑⍵}

```

Try it online!

Might as well put my own APL answer here, even if it is longer than Adám's. Takes vectors of vectors, and outputs vectors of vectors. The output with `[]` is a little funky as a result of this, the output is still `[]`, but it would be something akin to an empty vector of vectors.

-4 bytes thanks to looking at a portion of Razetime's answer.

# Answer
> 1 votes
# JavaScript (Node.js), 80 bytes

```
a=>v=>a.map(g=A=>A.map((_,i)=>A.map((_,j)=>x[j]=x[j]||v,x=a[i]=a[i]||[])))&&g(a)

```

Try it online!

# JavaScript (Node.js), 82 bytes

```
a=>v=>[a,...a].map(A=>A.map((_,i)=>A.map((_,j)=>x[j]=x[j]||v,x=a[i]=a[i]||[])))&&a

```

Try it online!

Can omit `&&a` claiming return to where `a` was

# Answer
> 1 votes
# Go, 144 bytes

```
func f(L[][]int)[][]int{d:=len(L)
for _,e:=range L{if len(e)>d{d=len(e)}}
for j,e:=range L{for i:=len(e);i<d;i++{L[j]=append(L[j],0)}}
return L}

```

Attempt This Online!

---
Tags: code-golf, array, ragged-list
---