# Question
Title: Maximum number of squares touched by a line segment
Consider a square grid on the plane, with unit spacing. A line segment of integer length \\$L\\$ is dropped at an arbitrary position with arbitrary orientation. The segment is said to "touch" a square if it intersects the interior of the square (not just its border).

# The challenge

What is the maximum number of squares that the segment can touch, as a function of \\$L\\$?

# Examples

* **L=3** \\$\ \\, \\$ The answer is \\$7\\$, as illustrated by the blue segment in the left-hand side image (click for a larger view). The red and yellow segments only touch \\$6\\$ and \\$4\\$ squares respectively. The purple segment touches \\$0\\$ squares (only the interiors count).
* **L=5** \\$\ \\, \\$ The answer is \\$9\\$. The dark red segment in the right-hand side image touches \\$6\\$ squares (note that \\$5^2 = 3^2+4^2\\$), whereas the green one touches \\$8\\$. The light blue segment touches \\$9\\$ squares, which is the maximum for this \\$L\\$.

# Additional rules

* The input \\$L\\$ is a positive integer.
* The algorithm should theoretically work for arbitrarily large \\$L\\$. In practice it is acceptable if the program is limited by time, memory, or data-type size.
* Input and output are flexible as usual. Programs or functions are allowed, in any programming language. Standard loopholes are forbidden.
* Shortest code in bytes wins.

# Test cases

Here are the outputs for `L = 1, 2, ..., 50` (with `L` increasing left to right, then down):

```
 3    5    7    8    9   11   12   14   15   17
18   19   21   22   24   25   27   28   29   31
32   34   35   36   38   39   41   42   43   45
46   48   49   51   52   53   55   56   58   59
60   62   63   65   66   68   69   70   72   73

```

# Answer
> 3 votes
# Vyxal, 7 bytes

```
*d⇩√3+⌊

```

Try it Online!

Shameless port of xnor's answer

```
*       # Square
 d      # Double
  ⇩     # Subtract 2
   √    # Square root
    3+  # Add 3
      ⌊ # Floor

```

# Answer
> 25 votes
# Python 2, 27 bytes

```
lambda L:(2*L*L-2)**.5//1+3

```

Try it online!

A direct formula:

$$ f(L) = \lfloor \sqrt{2 L^2-2}\rfloor + 3 $$

**Derivation**

As noted by @Kirill L. and others, the optimal layout uses a near-diagonal line segment whose horizontal and vertical span are at least \\$(h,h)\\$ or \\$(h,h+1)\\$. We need the length-\\$L\\$ to cover at least this much distance using the Pythagorean theorem, plus some extra to reach into squares and hit 3 more.

This gives a result of either:

* \\$2h+3\\$ where \\$h\\$ is the greatest positive integer where \\$h^2+h^2 \< L^2\\$, or
* \\$2h+4\\$ where \\$h\\$ is the greatest positive integer where \\$h^2+(h+1)^2 \<L^2\\$,

whichever of these is larger. We want to combine these two cases into one.

Let's start by making the two cases look more similar. Note that the second case can be rewritten as

> \\$2(h+\frac{1}{2})+3\\$, where \\$2(h+\frac{1}{2})^2 + \frac{1}{2} \< L^2\\$

or as

> \\$2h+3\\$, where \\$2h^2 + \frac{1}{2} \< L^2\\$

where \\$h\\$ is a positve integer-and-a-half. The \\$2h^2\<L^2\\$ in the first case can be also be written as \\$2h^2 +\frac{1}{2} \< L^2\\$, which is equivalent because both sides were integers. So, the cases now merge into:

> \\$2h+3\\$ where \\$h\\$ is the greatest positive integer or half-integer where \\$2h^2 +1/2 \< L^2\\$

Calling \\$2h=H\\$, this is:

> \\$H+3\\$ where \\$H\\$ is the greatest positive integer where \\$2(H/2)^2 +1/2 \< L^2\\$.

This inequality is \\$H^2 \< 2L^2-1\\$, and since these are integers, this is the same as \\$H^2 \leq 2L^2-2\\$. The greatest such positive integer \\$H\\$ is then \\$\lfloor \sqrt{2 L^2-2}\rfloor\\$, so the final result is \\$ \lfloor \sqrt{2 L^2-2}\rfloor + 3 \\$.

# Answer
> 13 votes
# , ~~79~~ 77 bytes

```
L=scan();j=1:L;a=j*2^.5;b=Mod(j+j*1i+1i);3+2*sum(L>a)+max(a[L>a],b[L>b])%in%b

```

Try it online!

*Note: as it turned out, this is completely destroyed by xnor's formula, which would be 23 bytes in R:*

```
(2*scan()^2-2)^.5%/%1+3

```

*However, I'm keeping the existing code as a reference to my original solution.*

### Original explanation

In general case, the most squares will be touched when the line is going close to the diagonal orientation. Specifically, the number of touched squares will be equal to \\$2 \times x + 3\\$, where \\$x\\$ is the number of unit square diagonals fully covered by the line. The lengths of square diagonals are stored in `a`.

However, in some cases a better coverage can be achieved by deviating from the diagonal orientation. To account for this, we also store a vector `b` containing the lengths of diagonals of "deviated" rectangles of size \\$1 \times 2\\$ up to \\$L \times (L+1)\\$ (instead of squares up to \\$L \times L\\$). It looks like we need to count one additional touch in those cases where the maximal value of `b` that is still smaller than \\$L\\$ exceeds the analogous value from `a`.

For example, the first few diagonals are of length:

```
 1x1       2x2       3x3       4x4
 1.414214  2.828427  4.242641  5.656854 ...

```

We can see that after going from \\$L = 3\\$ to \\$L = 4\\$ we have still covered only the 2nd term (\\$2 \times 2\\$ diagonal), it's not enough to reach the edge of the 3rd square, so we are not gaining any more touches. But if we switch to the "deviated" rectangles:

```
 1x2       2x3       3x4       4x5
 2.236068  3.605551  5.000000  6.403124 ...

```

Here \\$L = 4\\$ now encompasses a larger value of 3.60..., which corresponds to (\\$2 \times 3\\$) rectangle. In this orientation we gain an extra touched square compared to the diagonal.

# Answer
> 4 votes
# , 28 bytes

*-1 thanks to Jonah!*

The optimal is always either the diagonal `L, L` with `3+2*L` tiles crossed as noted by @Kirill L. or `L, L+1`, in which case an extra tile is crossed.

```
((>]+&.*:>:)+3+2*])[<.@%%:@2

```

Try it online!

* `[<.@%%:@2` calculate `L` by dividing `n` by `sqrt(2)`, then flooring
* `3+2*]` `3+2*L`
* `]+&.*:>:` calculate length to `L, L+1`
* `> … +` if `n` is larger than this length, add 1

Because the lines have rational length `n`, and the diagonals irrational length `L`, we can always find an epsilon \\$L - n \> 0\\$ to slide the line top-left to touch the 3 extra tiles, which justifies the `3+2*L`.

`L, L+2` will always be further away then the next diagonal `L+1, L+1`, as \\$L^2 + (L+2)^2 = 2L^2 + 4L + 4 \> 2L^2 + 4n + 2 = (L+1)^2 + (L+1)^2\\$, so checking `L, L+1` is enough.

# Answer
> 3 votes
# Jelly,  ~~18 17~~  8 bytes

-9 using xnor's mathematical simplification of the same method as the 17, below.

```
²Ḥ_2Æ½+3

```

A monadic Link that accepts a positive integer, \\$L\\$ and yields the maximal squares touched.

**Try it online!** Or see the test-suite.

### How?

```
²Ḥ_2Æ½+3 - Link: positive integer, L
²        - square -> L²
 Ḥ       - double -> 2L²
  _2     - subtract 2 -> 2L²-2
    Æ½   - integer square-root -> ⌊√(2L²-2)⌋
      +3 - add three

```

---

17:

```
²H½Ḟð‘Ḥ‘++²ḤƊ‘½<ʋ

```

**Try it online!**

### How?

First finds the longest \\$(a,a)\\$ or \\$(a,a+1)\\$ diagonal that \\$L\\$ can cover with some to spare, then places the line along this diagonal, poking out at both ends, and shifts it in the \\$x\\$ direction to cover \\$2a+3+X\\$ squares where \\$X=1\\$ if the diagonal is \\$(a,a+1)\\$, otherwise \\$X=0\\$.

```
²H½Ḟð‘Ḥ‘++²ḤƊ‘½<ʋ - Link: positive integer, L
²                 - square -> L²
 H                - halve -> L²/2
  ½               - square-root -> side of square with diagonal L
   Ḟ              - floor -> a
    ð             - new dyadic chain, f(a,L)...
     ‘            - increment -> a+1
      Ḥ           - double -> 2a+2
       ‘          - increment -> 2a+3
                ʋ - last four links as a dyad, f(a, L):
            Ɗ     -   last three links as a monad, f(a):
          ²       -     square -> a²
         +        -     (a) add (that) -> a+a²
           Ḥ      -     double -> 2(a+a²)
             ‘    -   increment -> 2(a+a²)+1 = a²+(a+1)²
              ½   -   square-root -> diagonal length of (a,a+1)
               <  -   less than (L)? -> 1 or 0 -> X
        +         - (2a+3) add (X)

```

# Answer
> 2 votes
# Perl 5, 73 bytes

```
for$d(0,1){$w=0;1while$w**2+($d+$w++)**2<$_**2;$m+=2*$w-1+$d}$_=int$m/2+1

```

Try it online!

Took @Kirill L.'s explanation and ran with it. Does two passes, without and with "deviation" in `$d`. The `int$m/2+1` outputs the average (rounded up if .5) of those two passes, which will be the max of those two results. Reads the wanted length from stdin and prints max number of squares for that length. The following bash command outputs max number of squares touched for all lengths 1 to 50:

```
for l in {1..50}; do
  echo $l | perl -pe \
  'for$d(0,1){$w=0;1while$w**2+($d+$w++)**2<$_**2;$m+=2*$w-1+$d}$_=int$m/2+1';
  echo -n " ";
done

3 5 7 8 9 11 12 14 15 17 18 19 21 22 24 25 27 28 29 31 32 34 35 36 38 39 41 42 43
45 46 48 49 51 52 53 55 56 58 59 60 62 63 65 66 68 69 70 72 73

```

# Answer
> 2 votes
# Japt, 10 bytes

```
Ò2nU²Ñ ¬ÄÄ

```

Try it

```
Ò2nU²Ñ ¬ÄÄ     :Implicit input of integer U
Ò              :Negate the bitwise NOT of (i.e., floor and increment)
 2n            :  Subtract 2 from
   U²          :    U squared
     Ñ         :    Times 2
       ¬       :  Square root
        ÄÄ     :Add one twice

```

# Answer
> 1 votes
# Retina, ~~43~~ 29 bytes

```
.+
**2*
(^_|\1__)*__+
__$#1*

```

Try it online! Link is to test suite that generates the results from `1` to the input. Explanation: Now using @xnor's formula.

```
.+
**2*

```

Double the square of `L` and convert it to unary.

```
(^_|\1__)*__+
__$#1*

```

Subtract `2` and take the integer square root. This is based on @MartinEnder's comment to my Retina answer to It's Hip to be Square but without the leading `^` anchor as the subtraction of `2` guarantees a single match.

```

```

Add a final `1` and convert to decimal.

Previous 43-byte solution based on @KirillL.'s answer:

```
.+
**
((^(_)|\2__)*)\1(\2_(_))?.+
__$2$3$5

```

Try it online! Link is to test suite that generates the results from `1` to the input. Explanation:

```
.+
**

```

Square `L` and convert it to unary.

```
((^(_)|\2__)*)\1(\2_(_))?.+

```

Find the largest `n` where `2n²<L²`, thereby dividing `L` by `√2`. Additionally, try to match a further `2n+1` (`\2` contains `2n-1`), because a rectangle of dimensions `n` by `n+1` has diagonal `√(2n²+2n+1)`. Match at least a further `1` so that the inequality is strict, but also because it guarantees a single match.

```
__$2$3$5

```

Calculate `2+2n`, plus add another `1` for the rectangular case. Note that `$2$3` is used because `\2` doesn't actually contain `2n-1` when `n=0`, but `$2$3` is always `2n`.

```

```

Add a final `1` and convert to decimal.

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

```
n=>(2*n*n-2)**.5+3|0

```

Try it online!

Shamelessly copies the idea from xnor's answer

# Answer
> 1 votes
# \>\<\>, 27 bytes

```
:*2*2-0v
:})?v1+>::*{
;n+2<

```

Try it online!

Xnor's formula, but in a language with neither square root nor rounding operations. Instead, it does the equivalent thing of finding the least square number larger than \\$2L^2 - 2\\$

# Answer
> 1 votes
# Java (JDK), 28 bytes

```
L->L+=Math.sqrt(2*L*L-2)+3-L

```

Try it online!

Same as everyone, I guess, cheers to xnor!

#### Same length as:

```
L->(int)Math.sqrt(2*L*L-2)+3

```

Try it online!

# Answer
> 1 votes
# Wolfram Language (Mathematica), 20 bytes (14 characters)

```
⌊√(2#^2-2)⌋+3&

```

Try it online!

Shamelessly translating xnor's Python answer.

# Answer
> 1 votes
# Stax, 7 bytes

```
é╟φQRl:

```

Run and debug it

# Answer
> 1 votes
# 05AB1E, 7 bytes

```
n·Ít3+ï

```

Port of *@xnor*'s Python answer, so using the same formula:

$$f(L) = \lfloor\sqrt{L^2+2}+3\rfloor$$

Try it online or verify the first 50 test cases.

**Explanation:**

```
n        # Square the (implicit) input-integer
 ·       # Double it
  Í      # Subtract it by 2
   t     # Take the square-root of that
    3+   # Increase it by 3
      ï  # Truncate/floor it to an integer
         # (after which the result is output implicitly)

```

# Answer
> 1 votes
# MathGolf, 7 bytes

```
²∞⌡√3+i

```

Port of *@xnor*'s Python answer, so using the same formula:

$$f(L) = \lfloor\sqrt{L^2+2}+3\rfloor$$

Try it online.

**Explanation:**

```
²        # Square the (implicit) input-integer
 ∞       # Double it
  ⌡      # Subtract it by 2
   √     # Take the square-root of that
    3+   # Increment it by 3
      i  # Convert it to an integer
         # (after which the entire stack is output implicitly as result)

```

---
Tags: code-golf, sequence, arithmetic, integer, grid
---


# Question
Title: Distances between keys on a QWERTY keyboard
*Inspired by this video by Matt Parker*

The distances between the letter keys of a QWERTY keyboard are somewhat standardised. The keys are square and both the horizontal and vertical spacing are 19.05mm (so if there were no gaps between the keys, their side lengths would be 19.05mm), and the three rows of keys are offset by ¼ and ½ a key size. Here is a diagram:

Your task is simple: given two letters, output the Euclidean distance between their centres (or between any two equivalent relative positions, for that matter) on a QWERTY keyboard as described above.

The rows of the QWERTY keyboard in a more easily copyable format are:

```
QWERTYUIOP
ASDFGHJKL
ZXCVBNM

```

`Q`, `A`, and `Z` are aligned to the left with only the ¼ and ½ offsets described above; the keys at the rightmost end (`P`, `L`, and `M`) do not line up as well.

Of course, given the same letter twice, your output should be 0.

## Rules

* You may accept input in uppercase or lowercase, and as characters, strings, or ASCII codepoints, but this must be consistent
    + You may assume the input will always be valid; behaviour for non-Latin-letters is undefined
* Your output must be in millimeters, and be accurate to within 0.1mm of the actual value
* You may use any reasonable I/O method
* Standard loopholes are forbidden
* This is , so the shortest code in bytes wins

## Test cases

A full list can be found here (original list calculated by Matt Parker, published here)

```
In  Out

A B 87.82
B Q 98.18
G C 34.34
H J 19.05
L J 38.10
P X 143.27
Y Y 0
4 K [behaviour undefined]

```

**Note**: of course *your* keyboard has different measurements. Of course *your* keyboard uses AZERTY, or Dvorak, or something else. Of course *your* keyboard is 3-dimensional with keys that aren't completely flat, so the distances vary a little. Of course *your* keyboard has wobbly keys that mean the distances aren't even constants. Of course *you* live in a universe with Heisenberg's Uncertainty Principle in which you cannot truly know that the keys are that far apart. **This is obviously an idealised model of a keyboard; please don't argue about these things in the comments!**

Image above modified from work by Denelson83 on English Wikipedia, used under CC-BY-SA 3.0.

# Answer
> 9 votes
# Jelly,  ~~25 24 23~~  21 bytes

-1 thanks to Nick Kennedy! (use of `)` to avoid repeated mapping)

-2 thanks to emanresu A! (Accuracy is only required to be within \\$0.1\\$mm of the true value)

```
ØQœi×4:3+ɗ\)ạ/×4.76ÆḊ

```

A monadic Link that accepts a list of two upper-case characters and yields a floating-point number.

**Try it online!** Or see the test-suite.

### How?

Finds horizontal and vertical distances measured in quarter-key lengths of \\$\frac{19.05}{4} = 4.7625\\$ then takes the norm of the vector (i.e. uses Pythagoras). Since \\$4.76\\$ is good enough\* for requirements, that is used as the quarter-key length.

```
ØQœi×4:3+ɗ\)ạ/×4.76ÆḊ - Link: characters, [A, B]
           )          - for each (c in [A, B]):
ØQ                    -   Qwerty keyboard -> ["Q..P","A..L","Z..M"]
  œi                  -   first multi-dimensional index of c in Qwerty keyboard
    ×4                -   multiply by four
                          -> [row(c)×4, column(c)×4]
          \           -   cumulative reduce by:
         ɗ            -     last three links as a dyad:
       3              -       three
      :               -       (row(c)×4) integer divide (3)  i.e. 4->1; 8->2; 12->4
        +             -       add (column(c)×4)  -> [row(c)×4, column(c)×4+(row(c)×4:3)]
                           (i.e. quarter steps down and right from a point a quarter
                                 left of the top-left of Q required to reach the bottom
                                 right of each of [A, B])
             /        - reduce by:
            ạ         -   absolute difference -> [vertical, horizontal] quarter steps
              ×4.76   - multiply by 4.7625 -> [vertical, horizontal] distances
                   ÆḊ - vector norm -> distance between keys

```

* Here is a suite showing all values are within \\$0.1\\$mm of the actual values - checking that all possible pairs using a quarter-key length of \\$4.76\\$ are within \\$0.1\\$ of those calculated using a quarter-key length of \\$4.7625\\$. (All results are actually also within \\$0.1\\$mm of Matt Parker's \\$2\\$ decimal place values - see this)

# Answer
> 6 votes
# , ~~145~~ ~~142~~ ~~138~~ ~~125~~ ~~124~~ ~~102~~ 100 bytes

*Edit: -4 bytes thanks to ovs*

```
function(x,j=2-sapply(x,regexpr,'lo,kimjunhybgtvfrcdexswzaq'))dist(cbind(y<-j%%3,j%/%3+2^y/4))*19.05

```

Try it online!

**Ungolfed**

```
qwertydist=function(x){     # x = input = vector of two characters
 k='lo,kimjunhybgtvfrcdexswzaq'
                            # k = 26-character vector of keys of each keyboard column exept last (in reverse).
 j=2-sapply(x,regexpr,k)    # j = indices of x in reversed k, & offset by a fixed value so that the missing 'p' ends-up in the right place
 y<-j%%3                    # y = row of each key
 z=j%/%3+2^y/4              # z = col of each key, adjusted +.25 for row 1 & +.5 for row 2
 d=dist(cbind(y,z))*19.05   # d = euclidean distance between keys, in millimetres
}

```

# Answer
> 5 votes
# Vyxal, 39 bytes

```
ƛ£k•ƛ¥v=;:vaThD£ɾ0p∑4/∇iTh+¥";÷∆d19.05*

```

Try it Online! -2 thanks to pxeger. +2 because of a bug

Ugh, what a mess.

Vyxal has several bugs right now, so the find command isn't working, among other things.

Takes a two-char string of lowercase letters.

```
ƛ                          ;            # Map...
 £                                      # Store to register
  k•ƛ   ;                               # Map rows of qwerty keyboard to...
     ¥v=                                # Is equal to register (current value)
         :                              # Duplicate this
          va                            # Foreach, check if any are true
            Th                          # Find the only truthy index - this is the correct keyboard row
              D£                        # Duplicate and store a copy to register
                ɾ0p∑4/                  # Horizontal offset of this row - nth triangle number/4 (There's probably a better way to do this, `0p` because Vyxal)
                      ∇                 # Shift, putting a copy of the  row number above the list of indices on the stack
                       i                # Index this into the list of indices
                        Th+             # Find the index of the key and add to previously calculated horizontal offset
                           ¥"           # Pair with vertical offset
                              ÷         # Iterate onto the stack
                               ∆d       # Pythagoras' Theorem
                                 19.05  # Multiply by 19.05

```

# Answer
> 5 votes
# JavaScript (ES6),  ~~114~~  113 bytes

*Saved 1 byte thanks to @Shaggy*

Expects `(a)(b)`.

```
a=>b=>Math.hypot((g=c=>(x="WERTYUIOPASDFGHJKLZXCVBNM".search(c))-[y=x>8,39,73][y+=x>17]/4)(a)-g(b,Y=y),y-Y)*19.05

```

Try it online!

# Answer
> 5 votes
# Python 3.8 (pre-release), ~~108~~ 97 bytes

```
lambda x,y:abs(p(x)-p(y))*4.76
p=lambda c:(a:='.LO,KIMJUNHYBGTVFRCDEXSWZAQ'.find(c))%3*4j+a--a//3

```

Try it online!

`p` maps a character to a complex number corresponding to its key's position, at a scale where the key size is 4; the magnitude of the difference of `p` of the given characters, rescaled, gives the answer.
`find` returning -1 when the substring is not found is used to handle P.

-2 using the suggestion of a decimal multiplier from emanresu A, taken one step further – with the value 4.76, the maximum error is slightly over 0.09, just within the limit.
-9 by transposing the keyboard and making some other changes with that.

# Answer
> 4 votes
# Charcoal, ~~60~~ 56 bytes

```
Ｉ×¹⁹·⁰⁵₂ΣＥ²Ｘ↨ＥＥθ⌕”&⌈‽↶ ›Ｉ✂ＴFsＧ�¦ιAo⊟↧”λ⎇ι﹪λ³⊘⊘÷⊗⊗⊕λ³±¹¦²

```

Try it online! Link is to verbose version of code. Takes input as a string of two lower case letters. Explanation: The compressed string contains the letters in a staggered arrangement. The vertical offset is simply the index modulo `3`, while the horizontal offset is computed by dividing the index by `3` and rounding to the nearest multiple of `0.25`. Pythagoras is then used to compute the final result.

```
         Ｅ²                             Loop twice (horizontally/vertically)
              Ｅθ                        Loop over input
                ⌕...λ                   Find char indices in compressed string
             Ｅ       ⎇ι                 Extract either
                       ﹪λ³              Vertical offset
                          ⊘⊘÷⊗⊗⊕λ³      Horizontal offset
           Ｘ↨                     ±¹¦²  Take the squared difference
        Σ                               Take the sum
       ₂                                Take the square root
 ×¹⁹·⁰⁵                                 Multiply by literal 19.05
Ｉ                                       Cast to string for implicit print

```

# Answer
> 4 votes
# 05AB1E, ~~33~~ ~~28~~ 27 bytes

-1 byte thanks to Kevin Cruijssen!

Builtins for multi-dimensional index and euclidean distance would be helpful. Takes input in lowercase.

```
vžVyδkZDŠkDŠÍo+‚}-nOt19.05*

```

Try it online!

**Commented:**

```
v               }   # iterate over each character y in the input
 žV                 # push ["qwertyuiop", "asdfghjkl", "zxcvbnm"]
   yδk              # for each row, find the index of the current char in it (-1 if not found)
      ZD            # get the maximum one (the only one not equal to -1) twice (call this x)
        Š           # rotate top 3 values on the stack (x [indices] x)
         k          # find the index of x in the indices (call this y)
          DŠ        # duplicate y and rotate top 3 values (y x y)
            Ío      # 2**(y-2)
              +     # add to x   (y x+2**(y-2))
               ‚    # pair up both values [y, x+2**(y-2)]

 -                  # take the element-wise differences
  nOt               # Euclidean norm (square, sum, square root)
     19.05*         # multiply by constant 19.05 (*1905/100 would be the same length with integer compression)

```

# Answer
> 4 votes
# Jelly, 23 bytes

```
ØQœi2*÷8Ʋ+¥\)ạ/ÆḊ×19.05

```

Try it online!

A monadic link taking a list of two characters and returning a float.

# Answer
> 3 votes
## Perl 5, 129 + 4 (`-apl` options) = 133 bytes

```
($x,$y,$u,$v)=map{$i=index+QWERTYUIOPASDFGHJKL_ZXCVBNM,$_;$==$i/10;$i%10+(0,1,3)[$=]/4,$=}@F;$_=19.05*sqrt(($x-$u)**2+($y-$v)**2)

```

Try it online!

# Answer
> 2 votes
# Ruby, 88 bytes

```
->a{p,q=a.map{|i|b=:_QAZWSXEDCRFVTGBYHNUJMIK_OL_P=~/#{i}/
b*4/3+-b%3*4i}
(p-q).abs*4.76}

```

Try it online!

Used a symbol instead of a string as suggested by Dingus. Also improved formula for converting `b` to a complex number (saved several bytes, although it requires another dummy character at the start of the string.)

# Ruby, 95 bytes

```
->a{p,q=a.map{|i|b='QAZWSXEDCRFVTGBYHNUJMIK<OL>P'.index i
b/3*4+b%3*3/2+b%3*4i}
(p-q).abs*4.76}

```

Try it online!

I used a `QAZ WSX`order because it splits into rows and columns by the application of `b/3 and b%3`, saving three bytes over the alternative `b/10` and `b%10`. `p` and `q` contain the coordinates as complex numbers, expressed as integer multiples of a quarter of a key. At the end we multiply by `4.76` which is in approximation of `19.05/4 = 4.7625`. The value `4.76*4 = 19.04` gives an error of `0.01mm` between two adjacent keys on the same row, giving a maximum error of `0.09mm` between `P` and `Q` which is within allowed limits.

---
Tags: code-golf, kolmogorov-complexity, geometry, keyboard
---


title: Polyagony layout (mode 3/3,6)

text:
# Question
Title: Polyagony layout (mode 3/3,6)
## Background

**Polyagony** is a family of hypothetical esolangs where the source code is laid out on a specifically shaped board before running it. It's similar to Hexagony, but various uniform tilings can be used instead of a simple hexagon. The shape of the board and the tiling used is defined by the "mode".

Mode 3/3,6 is a triangular board filled with (3,6)2 tiling. The boards of sizes 1, 2, and 3 look like the following:

```
 *      *          *
* *    * *        * *
      *   *      *   *
     * * * *    * * * *
               *   *   *
              * * * * * *

```

In general, the board of size `n` can be formed by adding two rows under the board of size `n-1`, where the two new rows are formed by putting `n` copies of small triangles side by side. So the size 4 can be generated from size 3 as follows:

```
       *
      * *
     *   *
    * * * *
   *   *   *
  * * * * * *
 1   2   3   4
1 1 2 2 3 3 4 4

```

Given a source code of length n, the size of the board is determined first, and then each character in the code is sequentially placed on each asterisk from top to bottom, left to right. The rest is filled with no-ops (dots, as in Hexagony).

The board size is chosen so that it is the smallest board that can fit the entirety of the source code. For example, `abcdefghi` would be placed as

```
   a
  b c
 d   e
f g h i

```

and `abcdefghij` as

```
     a
    b c
   d   e
  f g h i
 j   .   .
. . . . . .

```

The minimum board size is 1. If the source code is empty, the laid out result must be a triangle of three no-ops:

```
 .
. .

```

## Challenge

In order to simplify the challenge a bit, let's assume the source code is just a string of asterisks (`*`). Given the **length** of such a program as input, output the laid out result.

The output can be as a single string or a sequence of lines. Trailing whitespaces on each line or after the entire output are OK.

Standard rules apply. The shortest code in bytes wins.

## Test cases

The expected outputs for the inputs 0 (three no-ops), 3, 9, and 18 (full triangles of asterisks) are already given above.

```
Input: 2
Output:
 *
* .

Input: 4
Output:
   *
  * *
 *   .
. . . .

Input: 7
Output:
   *
  * *
 *   *
* * . .

Input: 17
Output:
     *
    * *
   *   *
  * * * *
 *   *   *
* * * * * .

```

# Answer
# Vyxal (hyper's old fork) `C`, ~~46~~ 45 bytes

```
3/d4Ė+√2Ė-⌈1∴:£ƛ‛% *Ṫ\%dn*"vṄ;f⁋?×*?d›\.*+f%↵

```

Try it Online!

Yuck. What a mess.

Uses the formula \\$\lceil\sqrt{\frac23x+\frac14}-\frac12\rceil\\$ to calculate the required size.

Mainstream Vyxal is completely broken right now - .

```
3...⌈                                   # Calculate above formula
     1∴                                 # Max(that, 1) for 0 case
       :£                               # Store a copy to register
         ƛ             ;                # Map...
          ‛% *                          # `% ` that many times
              Ṫ                         # With the last char removed
               \%dn*                    # 2n %s
                    "                   # Pair the two
                     vṄ                 # Join each by newline
                        f⁋              # Flatten and join by newlines
                          ?×*           # n *s
                             ?d›\.*+    # Plus 2n+1 .s
                                    f%  # Format the %s by this
                                      ↵ # Split by newlines so C can do its magic

```
> 6 votes

# Answer
# JavaScript (ES7),  ~~127~~  116 bytes

Draws the output character by character.

```
n=>(y=0,g=x=>y>w?'':`.*
 `[x<-w?(x=w,++y,2):x*x-->y*y|(y&1?x&1:~x&3^y&3)?3:n&&n/n--]+g(x))(w=(n*2/3-.4)**.5-.5<<1|1)

```

Try it online!

### How?

We define \\$w\\$ as:

$$w=\left\lfloor \sqrt{2n/3-2/5}-1/2 \right\rfloor\times2+1$$

The top of the triangle is \\$(0,0)\\$, the bottom-left corner is \\$(+w,+w)\\$ and the bottom-right corner is \\$(-w,+w)\\$.

```
   |    x > 0       x < 0
   |  <--------   -------->
   |  5 4 3 2 1 0 1 2 3 4 5
---+------------------------
 0 |  . . . . . B . . . . .
 1 |  . . . . A . A . . . .
 2 |  . . . B . . . B . . .
 3 |  . . A . A . A . A . .
 4 |  . B . . . B . . . B .
 5 |  A . A . A . A . A . A

```

There is an active cell on the board if \\$|x|\le y\\$ and:

* \\$y\\$ is odd and \\$x\\$ is odd (A-cells)
* or \\$y\\$ is even and \\$y\bmod 4 = x\bmod 4\\$ (B-cells)
> 6 votes

# Answer
# Charcoal, 40 bytes

```
ＮθＷ‹ＬＫＡ∨θ¹Ｆ⊞ＯυＬυ«Ｊ⊗⁻⊗κ⌈υ⊗⌈υＰ^²ＵＭＫＡ§.*‹μθ

```

Try it online! Link is to verbose version of code. Explanation:

```
Ｎθ

```

Input `n`.

```
Ｗ‹ＬＫＡ∨θ¹

```

Repeat until `n` characters have been output, except always output at least one character (this is a stupid edge case that costs me two bytes).

```
Ｆ⊞ＯυＬυ«

```

Loop through each triangle of the next row of the board.

```
Ｊ⊗⁻⊗κ⌈υ⊗⌈υ

```

Jump to the top of the triangle.

```
Ｐ^²

```

Print arbitrary characters down and left, thus creating the small triangle.

```
ＵＭＫＡ§.*‹μθ

```

Update all of the characters according to whether they are within the first `n` or not. (This is done inside the loop to save a byte, although only the last update actually matters.)
> 5 votes

# Answer
# , 76 69 bytes

*-7 bytes thanks to Jonah's approach!*

```
(' *.'{~]+(<]*$$+/\@,))1(<:2&(0&,.,a,._2{.])a=:#:@4 10)@>.+/\@i.I.%&3

```

Try it online!

* `+/\@i.` triangular numbers `0 1 3 6 …`
* `I.%&3` search for the index where `n%3` would sit inbetween. This is the (halved) height of the triangle.
* `1>.` corner case for 0
* `a=:#:@4 10` starting with the tile saved as `a`

```
0 1 0 0
1 0 1 0

```
* `_2{.]` get the last two rows
* `a,.` prepend `a` on the left
* `2&(0&,.,…)` prepend the previous rows with two 0 before them
* `<:` (with a bunch of `&`s) … do this (halved) height minus one times.
* `$$+/\@,` (would be cooler, if something like `+/\&.,` would work!) flatten to a list, scan-reduce with addition, and reshape to the 2d matrix. So

```
0 1 0 0 -> 0 1 0 0 1 0 1 0 -> 0 1 1 1 2 2 3 3 -> 0 1 1 1
1 0 1 0                                          2 2 3 3

```
* `]+(<]*` where it was 0 before, it shall be 0 after all. Compare with the input, and add to the original 2d matrix (so for `n=4`):

```
0 0 0 1 0 0 0
0 0 1 0 1 0 0
0 1 0 0 0 2 0
2 0 2 0 2 0 2

```
* `' *.'{~` map into the characters needed for the output
> 4 votes

# Answer
# Haskell, 269 bytes

```
import Data.List
f _ r[]=intersperse ' '<$>r
f n r s=let(x,y)=splitAt(3*n)s;(a,b)=splitAt n x in f(n+1)(map(' ':)r++[intersperse ' 'a,b])y
v[]=[]
v(x:y:s)=(' ':x):y:v s
s n=unlines$v$f 1[]$replicate n '*'++replicate(head(filter(>=n)$map(\n->(1+n)*n`div`2*3)[1..])-n)'.'

```

Clunky non-math solution. Generate a list of `*`s of length `n` and pad to nearest triangular number with `.`, then take out the characters two lines a time.

`f` generates the tower from list of asterisks and dots. `v` adjusts the tower so that it looks correct (very annoying). `s` generates the list of asterisks and dots, passes it to `f` and join the lines to give the result.
> 4 votes

# Answer
# Jelly, 48 bytes

```
RS×3R>¬
Ḥ÷3+.25½_.ĊðRżḤ$Rṁ@çị⁾*.ẎK€ÐoK€JU’Ɗ⁶ẋżƲY

```

Try It Online!

aaaaaaahh this is so bad... \>\_\<

even considering Jelly is not usually optimal for string challenges this feels like such a stupid solution

"borrows" A username's formula, \\$\lceil\sqrt{\frac23x+\frac14}-\frac12\rceil\\$

```
RS×3R>¬    Helper Link; given the size and the input, return the flat list of items
R          [1, 2, ..., size]
 S         Sum; nth triangular number
  ×3       Triple
    R      [1, 2, ..., 3/2 n(n+1)]
     >     For each one, is it greater than the input?
      ¬    Logical NOT; is it <= the input?

Ḥ÷3+.25½_.ĊðRżḤ$Rṁ@çị⁾*.ẎK€ÐoK€JU’Ɗ⁶ẋżƲY   Main Link
Ḥ÷3+.25½_.Ċ                                ×2 ÷3 +1/4 sqrt -1/2 ceil
           ð                               Dyadic chain; take the size on the left and the input on the right
            R                              [1, 2, ..., size]
             żḤ$                           Zip with double; [[1, 2], [2, 4], [3, 6], ...]
                R                          Range; [[[1], [1, 2]], [[1, 2], [1, 2, 3, 4]], [[1, 2, 3], [1, 2, 3, 4, 5, 6]], ...]
                 ṁ@                        Mold the right to the above:
                   ç                       Last link (the 1s and 0s for the output values)
                    ị⁾*.                   Index into "*."; 1 becomes * and 0 becomes .
                        Ẏ                  Tighten; flatten once
                         K€Ðo              Join odd indices on spaces
                             K€            Join each line on spaces
                               ====-=-Ʋ    4:
                               -=-Ɗ          3:
                               J               [1, 2, ..., # rows]
                                U              [#, # - 1, ..., 1]
                                 ’             [# - 1, # - 2, ..., 0]
                                   ⁶ẋ        " " * each
                                     ż       Zip with the original; format to triangle
                                       Y   Join on newlines

```
> 2 votes

# Answer
# Jelly, ~~38 37~~ 36 bytes

```
J’Ṛ⁶ẋż
‘RḤĖRðFJ>ṁ⁸ðȦÐḟȯ$Ẏị⁾.*K€⁺ÐoÇY

```

A monadic link that accepts a non-negative integer and yields a list of characters.

(Note: Removing the trailing `Y` *would* give a list of lines *but* each of those lines would be a list of lists of characters - the leading spaces in the first list and then the rest of the line in a second.)

**Try it online!** Or see the test-suite.

### How?

```
J’Ṛ⁶ẋż - Link 1, prefix spaces: list of lines with no leading spaces, L
J      - range of length [1..length(L)]
 ’     - decrement -> [0..length(L)-1]
  Ṛ    - reverse -> [length(L)-1..0]
   ⁶ẋ  - space character repeated -> [" ... ", ... , "  ", " ", ""]
     ż - (that) zipped with (L) -> [[" ... ", first], ... ["", last]]

‘RḤĖRðFJ>ṁ⁸ðȦÐḟȯ$Ẏị⁾.*K€⁺ÐoÇY - Main Link: non-negative integer, N
‘                             - increment -> N+1 (this is to create enough rows if N=0)
 R                            - range -> [1,2,3,...,N+1]
  Ḥ                           - double -> [2,4,6,...,2N+2]
   Ė                          - enumerate -> [[1,2],[2,4],[3,6],...,[N+1,2N+2]]
    R                         - range (vectorises) -> [[[1],[1,2]],[[1,2],[1,2,3,4]],...]
     ð     ð                  - dyadic chain, f(X=that, N):
      F                       -   flatten -> [1,1,2,1,2,1,2,3,4,...]
       J                      -   range of length -> [1,2,3,...,3(N+1)(N+2)/2]
        >                     -   greater than (N)? -> e.g. N=4: [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
         ṁ⁸                   -   mould like X
                                  -> e.g. N=4: [[[0],[0,0]],[[0,1],[1,1,1,1]],[[1,1,1],[1,1,1,1,1,1]],[[1,1,1,1],[1,1,1,1,1,1,1,1]],[[1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1]]],
                $             - last two links as a monad, f(Z=that):
             Ðḟ               -   filter discard those for which:
            Ȧ                 -     any and all?
                                  (removes those "row-pairs" which contain no zeros)
               ȯ              -   logical OR (with Z) (this is to keep [[[1],[1,1]]] when N=0)
                 Ẏ            - tighten -> e.g. N=4: [[[0],[0,0]],[[0,1],[1,1,1,1]]]
                  ị⁾.*        - index into ".*" -> ["*","**","*.","...."]
                      K€      - join each with spaces -> ["*","* *","* .",". . . ."]
                         Ðo   - apply to odd indexed entries:
                        ⁺     -   repeat last link -> ["*","* *","*   .",". . . ."]
                           Ç  - call last Link (Link 1) as a monad
                                -> [["   ","*"],["  ","* *"],[" ","*   ."],["",". . . ."]]
                            Y - join with new lines
                                ->   *
                                    * *
                                   *   .
                                  . . . .

```
> 1 votes

# Answer
# 05AB1E, 34 bytes

```
∞.ΔLO3*I@}·LL2Å€É}Ā».cT„. ‡IF¤'*.;

```

Try it online or verify all test cases.

**Explanation:**

```
∞             # Push an infinite positive list: [1,2,3,...]
 .Δ           # Find the first integer which is truthy for:
   L          #  Pop the integer `n`, and create a [1,n] ranged list
    O         #  Sum this list
     3*       #  Multiply it by 3
       I@     #  Check if it's larger than or equal to the input
 }·           # After we've found our integer: double it
   L          # Create a [1,n] ranged list again
    L         # Map each inner integer `m` into a [1,m] ranged list as well
     2Å€      # Apply to every (0-based) 2nd item (at indices 0,2,4,6,...):
        É     #  Check which integers are odd (1 if odd; 0 if even)
       }Ā     # Truthify: transform all other positive integers into 1s as well
»             # Join each inner list by spaces, and then each string by newlines
 .c           # Centralize each line by padding with leading spaces
T„. ‡         # Transliterate characters "10" to ". "
     IF       # Loop the input amount of times:
       ¤      #  Get the last character of the string without popping the string itself
              #  (which is always a ".")
        '*.; '#  And replace the first "." in the string with "*"
              # (after which the string is output implicitly as result)

```

Try this for a step-by-step of how the input is transformed into the output.
> 1 votes

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


title: Hexagonal section numbers

text:
# Question
Title: Hexagonal section numbers
## Introduction

Let's draw some regular hexagons formed by hexagonal tiles, marking the vertices of the tiles with dots. Then we will count the number of dots.

```
size 1: 6 dots
 . .
.   .
 . .

size 2: 24 dots
    . .
 . .   . .
.   . .   .
 . .   . .
.   . .   .
 . .   . .
    . .

size 3: 54 dots
       . .
    . .   . .
 . .   . .   . .
.   . .   . .   .
 . .   . .   . .
.   . .   . .   .
 . .   . .   . .
.   . .   . .   .
 . .   . .   . .
    . .   . .
       . .

```

Now, divide the hexagon into six identical sections, and keep the tiles that are needed to cover some of the sections. We still count the dots (vertices of the tiles) on the result.

```
size 3, one section: 22 dots
       . .
    . .   . .
 . .   . .   . .
.   . .   . .   .
 . .   @ @   . .
.   . @   @ @   .
 . .   @ @   @ @
.   . @   @ @   @
 . .   @ @   @ @
    . @   @ @
       @ @

size 3, two sections: 30 dots (38 and 46 dots for 3 and 4 sections respectively)
       . .
    . .   . .
 . .   . .   # #
.   . .   # #   #
 . .   @ @   # #
.   . @   @ @   #
 . .   @ @   @ @
.   . @   @ @   @
 . .   @ @   @ @
    . @   @ @
       @ @

size 3, five sections: 53 dots
       $ $
    * $   $ $
 * *   $ $   # #
*   * $   # #   #
 * *   @ @   # #
+   * @   @ @   #
 + +   @ @   @ @
+   + @   @ @   @
 + +   @ @   @ @
    . @   @ @
       @ @

```

Let's define \\$H(n,k)\\$ as the number of dots in the diagram of size \\$n\\$ with \\$k\\$ sections. It is guaranteed that \\$1 \le n\\$ and \\$1 \le k \le 6\\$.

## Challenge

Given the values of \\$n\\$ and \\$k\\$, calculate \\$H(n,k)\\$.

Standard rules apply. The shortest code in bytes wins.

The following is the table of values for small \\$n\\$:

```
     | k=1 k=2 k=3 k=4 k=5 k=6
-----+------------------------
n=1  |   6   6   6   6   6   6
n=2  |  13  16  19  22  24  24
n=3  |  22  30  38  46  53  54
n=4  |  33  48  63  78  92  96
n=5  |  46  70  94 118 141 150
n=6  |  61  96 131 166 200 216
n=7  |  78 126 174 222 269 294
n=8  |  97 160 223 286 348 384
n=9  | 118 198 278 358 437 486
n=10 | 141 240 339 438 536 600
n=11 | 166 286 406 526 645 726
n=12 | 193 336 479 622 764 864

```

\\$H(n,1)\\$ is equal to A028872(n+2). \\$H(n,2)\\$ is equal to A054000(n+1). \\$H(n,6)\\$ is equal to A033581(n). OEIS doesn't have the other three columns. Each column has its own formula, except for \\$H(1,5)\\$ :)

# Answer
> 7 votes
# Python 2, 38 bytes

```
lambda n,k:k*n*n+(4*n-k+2-k/5%n)*(k<6)

```

Try it online!

Not sure about its correctness. But it at least passed all testcases.

* -2 bytes by dingledooper
* -5 bytes by xnor

# Answer
> 1 votes
# Charcoal, 75 bytes

```
≔⁻²⪪024420¹ε≔⁻²⪪343101¹δＮθＦＮＦθ«Ｊ×κ§ε⊖ι×κ§δ⊖ιＦ⊕κ«ＧＨV→^←².Ｍ§ε⊕ι§δ⊕ι»»≔ＬＫＡζ⎚Ｉζ

```

Try it online! Link is to verbose version of code. Takes input as size and sections. Explanation: Far too long because it doesn't try to use a formula, but guarantees 100% correct answers.

```
≔⁻²⪪024420¹ε≔⁻²⪪343101¹δ

```

Create displacement vectors for each of the six hexagonal directions.

```
Ｎθ

```

Input the size.

```
ＦＮ

```

Loop over each section.

```
Ｆθ«

```

Loop over each size.

```
Ｊ×κ§ε⊖ι×κ§δ⊖ι

```

Start each row of hexagons one step further away from the middle.

```
Ｆ⊕κ«

```

Loop over each row.

```
ＧＨV→^←².

```

Draw a hexagon. (This hexagon is slightly horizontally compressed compared to the one in the question, as it made it easier to draw a six-dotted hexagon.)

```
Ｍ§ε⊕ι§δ⊕ι

```

Move to the next hexagon in the row.

```
»»≔ＬＫＡζ

```

Count the number of dots.

```
⎚Ｉζ

```

Clear the canvas and output the result.

# Answer
> 0 votes
# JavaScript (Node.js), 38 36 bytes

```
n=>k=>n*n*k+(k<6&&n*4+2-k-(n>1&k>4))

```

-2 bytes thanks to Shaggy

Try it online!

# Answer
> 0 votes
# 05AB1E, 19 bytes

Port of *@tsh*'s Python answer, so make sure to upvote him!

The inputs are in the order \\$n,k\\$.

```
4*²D5÷¹%ÆÌ²6‹*¹n²*+

```

Try it online or verify all test cases.

Or alternatively:

```
n*²6‹iU5÷¹%-¹4*αX2O

```

Try it online or verify all test cases.

**Explanation:**

```
4*                   # Multiply the first (implicit) input `n` by 4
  ²D                 # Push the second input `k` twice
    5÷               # Integer-divide the second one by 5
      ¹%             # And then modulo it by the first input `n`
        Æ            # Reduce all three values on the stack by subtracting
         Ì           # Increase it by 2
          ²6‹        # Check if the second input `k` is smaller than 6
             *       # Multiply this to the earlier value
              ¹n     # Push the first input `n` squared
                ²*   # Multiply it to the second input
                  +  # And add the two together
                     # (after which the result is output implicitly)

n                    # Square the first (implicit) input `n`
 *                   # Multiply it to the second (implicit) input `k`
  ²6‹i               # If the second input `k` is smaller than 6:
      U              #  Pop the earlier value and save it in variable `X`
       5÷            #  Integer-divide the second (implicit) input `k` by 5
         ¹%          #  And then modulo it by the first input `n`
           -         #  Subtract it from the second (implicit) input `k`
            ¹4*      #  Push the first input `n`, and multiply it by 4
               α     #  Get the absolute difference between the two values
                X    #  Push `X` back to the stack
                 2   #  Push 2
                  O  #  And sum the three values on the stack together
                     # (after which the result is output implicitly)

```

---
Tags: code-golf, math, integer, hexagonal-grid
---


title: Sum It Up with a Digital Triangle

text:
# Question
Title: Sum It Up with a Digital Triangle
Well, sum it down really.

Write a program or function that takes in a nonempty list of decimal integers (0-9) and outputs a downward pointing "triangle" of digits with the input list at the top where every digit after the first line is the sum of the two digits above it modulo 10.

For example, the input `[7, 5, 0, 9]` has output

```
7 5 0 9
 2 5 9
  7 4
   1

```

because `2` is `(7 + 5) mod 10`, `5` is `(5 + 0) mod 10`, `9` is `(0 + 9) mod 10`, etc. all the way to `1` being `(7 + 4) mod 10`.

If the list has only one item, then the output matches the input; e.g. an input of `[4]` will yield

```
4

```

Here are some additional examples:

```
[0]

0

[1, 2]

1 2
 3

[8, 7]

8 7
 5

[0, 0]

0 0
 0

[1, 4, 2]

1 4 2
 5 6
  1

[0, 1, 0]

0 1 0
 1 1
  2

[1, 0, 0, 0]

1 0 0 0
 1 0 0
  1 0
   1

[1, 2, 3, 4]

1 2 3 4
 3 5 7
  8 2
   0

[1, 2, 3, 5, 8]

1 2 3 5 8
 3 5 8 3
  8 3 1
   1 4
    5

[9, 2, 4, 5, 3, 2, 2]

9 2 4 5 3 2 2
 1 6 9 8 5 4
  7 5 7 3 9
   2 2 0 2
    4 2 2
     6 4
      0

```

Note that in the output:

* The first line does not have leading spaces.
* Each subsequent line has one more leading space than the line previous.
* Digits are separated by a single space.
* Each line is allowed to have up to one trailing space.
* There may be a single optional trailing newline.
* You must use the characters for normal decimal digits (0 through 9).

**The shortest code in bytes wins. Tiebreaker is earlier answer.**

# Answer
> 24 votes
# BrainF\**k, ~~396~~ 391 bytes

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

```

I couldn't resist the temptation to do this one. At least the triangle is pointy-side down.

Input comes in as a string of numeric characters followed by a single newline.

Output will contain a single trailing space on every line.

Examples:

```
$ bf sd.bf
010
0 1 0
 1 1
  2

$ bf sd.bf
123456
1 2 3 4 5 6
 3 5 7 9 1
  8 2 6 0
   0 8 6
    8 4
     2

$ bf sd.bf
9245322
9 2 4 5 3 2 2
 1 6 9 8 5 4
  7 5 7 3 9
   2 2 0 2
    4 2 2
     6 4
      0

```

## Explanation

Since it's rather difficult to explain the code from a functional perspective, we can instead look at it from the perspective of the state of the tape at various times. The core idea here is that the triangle we output is initialized as a tightly-packed (for BF, anyway) array that shrinks in size by 1 every iteration of a loop. Another important thought is that we use `255` to indicate a "placeholder" that we can search for on the tape.

### Initialization

This is the easiest step. At the start of the program, we execute the following:

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

```

This forces the tape into the following state (where `>N<` indicates the location of the pointer on the tape)

```
[ 0 1 32 255 >0< 0 0 ...]

```

The first number here is a "buffer" location. We're not going to use it on a long-term basis, but it's useful to make little operations simpler and for copying data around.
The second number is the number of spaces that we'll be outputting at the start of each line, starting *after* the first line. The first line will have no leading spaces.
The third number is the space character we output.
The fourth number is a placeholder 255, so that we can get back to this position relatively easily.

### Input

From this position, we will read in all of the characters. At the end of this step, we hope to be in the following situation:

```
[ 0 1 32 255 a b c d e f ... >255< 0 0 ... ]

```

Where `a b c d e f ...` indicates the string of numeric characters that was input (not the newline).

We accomplish this with the following:

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

```

There are some nuances to this. First of all, we will output each character as we get them, and then output a space after it. Secondly, we don't want to copy the ASCII value to the tape, we want to copy the actual numeric digit. Third, we want to stop when we hit a newline and leave ourselves in a good place at that time.
Say our input is `6723`. Then, upon reading the first `6`, our tape looks like this:

```
[ 0 1 32 255 >54< 0 0 ...]

```

We check that this value is not equal to `10` (an ASCII newline) with `,----------[++++++++++`. We then print out the value and continue by simultaneously subtracting 48 from the input value and adding 32 to the value next to it (`>>++++++++[-<++++<------>>]<`), leaving us here:

```
[ 0 1 32 255 6 >32< 0 ...]

```

Notice how throughout this process we can assume that all digits to the right of our input are 0--this means that we're not in danger of ruining any previous state if we use values to the right to calculate `6 * 8` and `4 * 8`.
Now we output the space character we just generated, and take in a new input, deleting the space we calculated there. Eventually, the input will be terminated by a new line and the loop will exit, leaving a `255` where the newline would have been (`,----------]-`). This is the second placeholder character we will use to navigate the tape. At this point in our scenario, our tape is exactly this:

```
[ 0 1 32 255 6 7 2 3 >255< 0 0 ... ]

```

### Calculation

The way this works is that the list of digits between our `255` placeholders is going to shrink by one every iteration of the loop. When it only has 1 digit left in it, we're done and should halt immediately (Note that, at this point, every digit in that list has already been output, so we don't have to worry about outputting it again).

We now use this trick to navigate to the first `255` placeholder: `<+[-<+]-`. This effectively searches the tape to the left for a `255`, changing nothing in between. Now that we've moved the pointer, we can check our exit condition: if there's only one digit in the list, then the cell two spaces to the right will hold `255`. Thus, we check against that and start a loop: `>>+[-<<`

The first step in our loop is to output a newline. So we move to the first cell (our buffer cell), add 10 to it and output. The next step is to output all leading space characters. After outputting them, we increment our count for number of leading spaces. These steps are accomplished by the following:

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

```

Which leaves us in this state:

```
[ 0 2 32 255 >6< 7 2 3 255 0 0 0 0 0 0 ]

```

Our next step is to copy the first value in the list over, past the second placeholder `255`:

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

```

We essentially do this by hopping back and forth between our placeholder `255`s, leaving us here:

```
[ 0 2 32 255 >0< 7 2 3 255 0 6 0 0 ... ]

```

We now start a loop, iterating through the rest of the list, stopping when we hit `255` : `>+[-<`

At this point, the digit to our immediate left is always 0. So, because we love them, we pop a placeholder `255` in there so that we can come back to our place in the list. The next step is to move the second place in the list to locations surrounding where we moved the first place to, past the second placeholder `255`. These steps are accomplished by the following:

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

```

Leaving us here: `[ 0 2 32 255 255 >0< 2 3 255 7 6 7 0 ]` Now, both the `6` and `7` have been moved to a location where the calculation can occur. We need two copies of the `7` because the next number in the list will need it as well. The `7` immediately after the `255` serves this purpose, whereas the other `7` will be consumed by the calculation.

First, we add the two digits:

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

```

Leaving us here:

```
[ 0 2 32 255 0 255 2 3 255 7 0 >13< 0 ]

```

The next combination of steps is the most complicated. We need to see if the number we're pointing to is larger than 10, and if it is, we subtract `10`. In reality, what we do is we subtract 10 from it and see if it hits `0` at any point in the subtraction. If it does, we add `10` back on later. At the end of this, we should have the sum modulo 10.

```
Prepare a 10 to the right
+>++++++++++
Leave yet another 255 for a loop condition later
>>-<<
If the number is greater than 10 end up one space to the left
else one space to the right
[-<-[>>]<]<->
Check if the previous 255 is two spaces to the right and if it is
add 10 back to our sum--we've subtracted too much
>>+[-<<<+>>>[-<->]<+++++++++>>>+]

```

At this point, we've accomplished the goal. We have the sum modulo 10! Also, whether or not the number was greater than 10, we'll end up here:

```
[ 0 2 32 255 0 255 2 3 255 7 0 3 0 0 >0< ]

```

Our next goals are to output this new sum, follow it with a space, and inject it back into our list. We do this all with our previous techniques of `255`-hopping and adding `48` to our sum, so I won't cover it in detail.

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

```

And we're here: `[ 0 2 32 255 3 255 2 3 255 7 0 0 51 >32< ]` Notice how we put an additional `255` placeholder after our newly-injected `3` so that we don't lose place in the list. At this point, we have output our sum and its space, so we need to clean up and revert to a state where the next iteration of this loop is going to work. We need to clear out our `51` and `32` cells, move the `7` once to the right, and navigate to our list placeholder so that we can start over.

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

```

Now, we're here: `[ 0 2 32 255 3 >0< 2 3 255 0 7 0 ... ]`
Which is exactly where we want to be for our next iteration. So check for 255 and move on! (`>+]`)

When we get dropped off from the loop, we're going to have a whole new list--made up of the sums from the previous list. The first time, it'll look like this:

```
 [ 0 2 32 255 3 9 5 0 >0< ]

```

Now we want to repeat that whole process on our new list, so we plop a `255` down to the left and start all over! We need to do a little bit of cleanup with `>>[-]<<`, and then drop our placeholder with `<-`. After that, we're in exactly the same place as we were after input, so we can get away with doing the same checks: `<+[-<+]->>+`, and boom! We've got our full loop! All we need is the closing bracket, and when it ends we've already output everything, so we're done: `]`.

# Answer
> 7 votes
# Jelly, ~~20~~ ~~19~~ 18 bytes

```
Ṛ+2\ṖÐ¿%⁵z”@ṚZGḟ”@

```

Try it online!

### Background

Generating the numbers is straightforward in Jelly. The output is a bit more complicated.

Jelly has a built-in grid atom (`G`) that displays a 2D list with newlines between rows and spaces between columns. We take the 2D array of numbers (generated with each row reversed), and transpose it with fill value `@`. After revering the resulting array and transposing again, applying `G` yield the following.

```
9 2 4 5 3 2 2
@ 1 6 9 8 5 4
@ @ 7 5 7 3 9
@ @ @ 2 2 0 2
@ @ @ @ 4 2 2
@ @ @ @ @ 6 4
@ @ @ @ @ @ 0

```

To obtain the desired triangular shape, all we have to do is remove the fill value.

### How it works

```
Ṛ+2\ṖÐ¿%⁵z”@ṚZGḟ”@  Main link. Argument: A (list of integers)

Ṛ                   Reverse A.
    ṖÐ¿             While there's more than one element:
 +2\                  Compute the pairwise sum.
                    Collect all intermediate results in a list.
       %⁵           Take all resulting integers modulo 10.
         z”@        Transpose with fill value '@'.
            Ṛ       Reverse the order of the rows.
             Z      Transpose.
              G     Grid.
               ḟ”@  Filter; remove the fill value.

```

# Answer
> 5 votes
# Pyth - 18 bytes

```
j.e+*dkjdbP.ueM+Vt

```

Test Suite.

```
j                                       Join by newlines
 .e                                     Loop over seq in var b and index in var k
  +                                     Concatenate
   *dk                                  Space repeated k times
    jdb                                 Join b by spaces
  P                                     [:-1] to get rid of empty line
   .u             (Q implicit)          Cumulative fixed point over input (var G)
    eM                                  Mod 10 mapped over list
     +V                                 Vectorized addition
      t(G implict)                      G[1:]
      (G implict)                       Vectorize cuts this off to G[:-1]

```

# Answer
> 5 votes
# 05AB1E, ~~20~~ ~~19~~ 17 bytes

Code:

```
DvNð×?T%Ððý,¦‚ø€O

```

Explanation:

```
D                     # Duplicate the input.
 v                    # Map over it, running the following len(input) times.
  Nð×                 # Multiply the iteration number with a space.
     ?                # Pop and print without a newline.
      T%              # Take all integers modulo 10.
        Ð             # Triplicate the array.
         ðý,          # Join by spaces and print with a newline.
            ¦         # Remove the first element of the array.
             ‚        # Wrap it up, (pop a, b push [a, b]).
              ø       # Zip.
               €O     # Sum up each element.

```

Uses the **CP-1252** encoding. Try it online!.

# Answer
> 5 votes
## Python 3.5, ~~74~~ ~~72~~ 71 bytes

```
f=lambda L,*S:f([sum(x)%10for x in zip(L,L[1:print(*S,*L)]or 1)],'',*S)

```

Input is a list of integers (e.g. `f([1,2,3,5,8])`), output is to STDOUT. The `%10` and the fact that `map` returns a `map` object in Python 3 is a bit annoying, meaning we can't do `map(lambda*x:sum(x)%10,L,L[1:])` or similar.

The function errors out, but by then the output would have completed. Thanks to @xsot for -1 byte by finding a good place to stick the `print`.

# Answer
> 4 votes
# MATL, ~~32~~ ~~30~~ ~~29~~ ~~28~~ ~~27~~ ~~26~~ ~~25~~ 24 bytes

```
t"X@qZ"y1X9&VhDTTH&Y+10\

```

*1 Byte saved thanks to @Luis*

**Try it Online!**

Modified version for all test cases

**Explanation**

```
        % Implicitly grab input
t       % Duplicate the input
"       % For each element of the input (really just a shortcut to loop numel(input) times)
  X@q   % Determine the current loop index and subtract 1
  Z"    % Create an array of blanks this size (these are the padding to the left)
  y     % Copy the current array of numbers from the stack
  1X9   % Get the pre-defined output format of %.15g from the clipboard
  &V    % Convert the input to it's character representation with single spacing
  h     % Horizontally concatenate the left padding and the numbers
  D     % Display the result (consumes the string)
  TT    % Create a two-element vector of 1's ([1 1])
  H&Y+  % Convolve [1 1] with the array (computes the pair-wise sum)
  10\   % Mod 10 the result
        % Implicitly close for loop

```

# Answer
> 2 votes
## Actually, 43 bytes

```
;l;D+#"{:^%d}"%╗W;' j1╟╜f.;pXZ`i+9u@%`MdXWX

```

Try it online!

This program prints a single trailing newline after the output.

Explanation:

```
;l;D+#"{:^%d}"%╗W;' j1╟╜f.;pXZ`i+9u@%`MdXWX
;l;D+                                        calculate the width of the field (2L-1 where L = len(input))
     #"{:^%d}"%╗                             push to a list, make a Python new-style format string for centering text, save in reg0
                W;' j1╟╜f.;pXZ`i+9u@%`MdXW   while the top of the stack is truthy:
                 ;' j1╟                        duplicate list, join with spaces, push string to a list
                       ╜f.                     center string and print
                          ;pXZ                 zip list with itself shifted forward by 1 (zip(a,a[1:]))
                              `i+9u@%`M        map: add each pair and mod by 10
                                       dX      discard the last value (which was not added with anything)
                                          X  discard the now-empty list after the loop to avoid printing it

```

# Answer
> 2 votes
# Mathematica, 67 Bytes

```
MatrixForm@NestList[Mod[Total/@Partition[#,2,1],10]&,#,Length@#-1]&

```

Example:

# Answer
> 2 votes
## CJam, 25 bytes

```
q~{_2ew::+Af%}h;]eeSff*N*

```

Try it online!

### Explanation

This uses a fairly neat trick to generate the triangle layout.

```
q~      e# Read and evaluate input.
{       e# While the list of digits is non-empty...
  _2ew  e#   Duplicate and get all sublists of length 2.
  ::+   e#   Sum each pair.
  Af%   e#   Take each result modulo 10.
}h
;]      e# Discard the final empty list and wrap the others in an array.
ee      e# Enumerate the array. E.g. for input `[7 5 0 9]` we now get this:
        e# [[0 [7 5 0 9]]
        e#  [1 [2 5 9]]
        e#  [2 [7 4]]
        e#  [3 [1]]]
Sff*    e# Perform S* on each element at depth two. For the integers from the
        e# enumeration this gives a string of that many spaces, i.e. the correct
        e# indentation. For the lists of digits this inserts a space character
        e# between every two digits, thereby spacing out the digits as necessary.
N*      e# Put linefeeds between the pairs of indentation and digit list.

```

# Answer
> 2 votes
# Haskell, 88 bytes

```
f=mapM putStrLn.(""%)
s%x@(_:y)=(s++(x>>=(:" ").last.show)):(' ':s)%zipWith(+)x y
_%_=[]

```

Try it online!

I chose the same I/O format and counted `f=` to compete fairly with the other Haskell answer.

Replacing the first line by just `(""%)` would give a 72-byte answer that returns a list of lines.

Instead of writing `show.(`mod`10)` or `[mod(a+b)10|(a,b)<-zip x y]`, it turns out to be shorter to use `last` on the result of `show`, which is kinda cute.

# Answer
> 1 votes
# JavaScript (ES6) 147 bytes

```
a=>{o=0;e=(c=>console.log(' '.repeat(o++)+c.join` `));l=1;while(l){p=0,d=[],e(a),a.map(b=>{p?d.push((v+b)%10):0;p=1,v=b});d.length<2?l=0:a=d};e(d)}

```

# Answer
> 1 votes
# Julia, ~~60~~ 59 bytes

```
\(x,s="")=x==[]?"":s*join(x," ")"
"*(diag(x'.+x,1)%10\" "s)

```

Based on @Sp3000's answer. The function `\` accepts an array as input and returns a string.

Try it online!

# Answer
> 1 votes
# Perl 6,  ~~65 63 62~~  61 bytes

```
~~{put ' 'x my$++,$_ for @_,{.rotor(2=>-1).map(*.sum%10).list}...1}
{put ' 'x my$++,$_ for @_,{@(.rotor(2=>-1).map(*.sum%10))}...1}
{put ' 'x my$++,$_ for @_,{@(map *.sum%10,.rotor(2=>-1))}...1}~~
{put ' 'x my$++,$_ for @_,{[map *.sum%10,.rotor(2=>-1)]}...1}
```

### Explanation:

```
{ # anonymous block that takes the list as input (@_)

  put # print with trailing newline

    ' ' x ( my $ )++, # pad with one more space than previous iteration
    $_                   # the list to print for this iteration
    # The ｢.Str｣ method on a List puts spaces between elements
    # which is what ｢put｣ calls on anything that isn't a Str

  for # do that for every list produced from the following

    @_, # the input list

    { # anonymous block that takes the previous list as input ($_)

      [ # turn the following from a Seq into an Array

        map
          *.sum % 10, # sum the values and modulus 10 of the following:

          # take the previous list 2 at a time, backing up one
          $_.rotor( 2 => -1 )

      ]

    }

    ... # repeatedly call that block until:

    1   # the result is only one element long
}

```

### Example:

```
my &digital-triangle-sum = {put ' 'x my$++,$_ for @_,{[map *.sum%10,.rotor(2=>-1)]}...1}

for [7,5,0,9], [0,1,0], [1,0,0,0], [9,2,4,5,3,2,2] -> \List {
   digital-triangle-sum List

   put '';
}

```

```
7 5 0 9
 2 5 9
  7 4
   1

0 1 0
 1 1
  2

1 0 0 0
 1 0 0
  1 0
   1

9 2 4 5 3 2 2
 1 6 9 8 5 4
  7 5 7 3 9
   2 2 0 2
    4 2 2
     6 4
      0

```

# Answer
> 1 votes
# Java 7, ~~230~~ ~~215~~ 213 bytes

```
int c=0;void m(int[]a){int l=a.length,j=-1,i=-1;if(l<1)return;int[]x=new int[l-1];while(++j<c)p(" ");for(;++i<l;p(a[i]+" "))if(i<l&i>0)x[i-1]=(a[i-1]+a[i])%10;p("\n");c++;m(x);}<T>void p(T s){System.out.print(s);}

```

This ended up being a bit longer than I thought.. Maybe it can be golfed a bit more though, since I kinda messed up I think..

Some bytes saved thanks to *@GiacomoGarabello*.

**Ungolfed & test code:**

Try it here.

```
class Main{
  static int c = 0;

  static void m(int[] a){
    int l = a.length,
        j = -1,
        i = -1;
    if(l < 1){
      return;
    }
    int[] x = new int[l-1];
    while(++j < c){
      p(" ");
    }
    for(; ++i < l; p(a[i] + " ")){
      if(i < l & i > 0){
        x[i - 1] = (a[i - 1] + a[i]) % 10;
      }
    }
    p("\n");
    c++;
    m(x);
  }

  static <T> void p(T s){
    System.out.print(s);
  }

  static void printAndReset(int[] a){
    m(a);
    c = 0;
    System.out.println();
  }

  public static void main(String[] a){
    printAndReset(new int[]{ 7, 5, 0, 9 });
    printAndReset(new int[]{ 0 });
    printAndReset(new int[]{ 1, 2 });
    printAndReset(new int[]{ 8, 7 });
    printAndReset(new int[]{ 0, 0 });
    printAndReset(new int[]{ 1, 4, 2 });
    printAndReset(new int[]{ 0, 1, 0 });
    printAndReset(new int[]{ 1, 0, 0, 0 });
    printAndReset(new int[]{ 1, 2, 3, 4 });
    printAndReset(new int[]{ 1, 2, 3, 5, 8 });
    printAndReset(new int[]{ 9, 2, 4, 5, 3, 2, 2 });
  }
}

```

**Output:**

```
7 5 0 9
 2 5 9
  7 4
   1

0

1 2
 3

8 7
 5

0 0
 0

1 4 2
 5 6
  1

0 1 0
 1 1
  2

1 0 0 0
 1 0 0
  1 0
   1

1 2 3 4
 3 5 7
  8 2
   0

1 2 3 5 8
 3 5 8 3
  8 3 1
   1 4
    5

9 2 4 5 3 2 2
 1 6 9 8 5 4
  7 5 7 3 9
   2 2 0 2
    4 2 2
     6 4
      0

```

# Answer
> 1 votes
## Pyke, 21 bytes

```
lVDm}R$],FsT%)od*pKDP

```

Try it here!

I'd like to think this method's a little bit different.

```
[1, 2, 3, 5, 8] - take the input
[2, 4, 6, 10, 16] - double it
[1, 2, 3, 5, 8] - take the input again
[1, 1, 2, 3] - get the deltas
[[2,1], [4,1], [6,2], [10,3]] - transpose them together
[3, 5, 8, 13] - apply addition
[3, 5, 8, 3] - mod 10

```

# Answer
> 1 votes
# TSQL, ~~198~~ ~~194~~ 191 bytes

By using GOTO instead of one of the WHILE, I was able to golf 3 characters

Golfed

```
DECLARE @ varchar(100)= '1 2 3 4 5 6 7'

DECLARE @j INT=1,@i INT=LEN(@)a:
PRINT @
WHILE @i>@j
SELECT
@=STUFF(@,@i-1,2,RIGHT(SUBSTRING(@,@i-2,1)+SUBSTRING(@,@i,1)*1,1)+' '),@i-=2SELECT
@=STUFF(@,@j,1,' '),@j+=1,@i=LEN(@)IF @i>0GOTO a

```

Try it online(using old script with 2\*WHILE)

# Answer
> 1 votes
## JavaScript (ES6), 77 bytes

```
a=a.map((_,i)=>(b=a,a=[a.map((e,j)=>j>i?(e+a[j-1])%10:''),b.join` `)).join`
`

```

# Answer
> 1 votes
# C# 6, ~~125+31~~ 125+18 = 143 bytes

```
string f(int[] n,string s="")=>s+string.Join(" ",n)+"\n"+(n.Length>1?f(n.Zip(n.Skip(1),(a,b)=>(a+b)%10).ToArray(),s+" "):"");

```

The +18 is for `using System.Linq;`

*Thanks to @TheLethalCoder for saving 13 bytes, by pointing out a unnecessary using statement*

# Answer
> 1 votes
# Vyxal `C`, 10 bytes

```
λḢ+Ṫ₀%;↔vṄ

```

Try it Online!

```
λ     ;    # Push a lambda
 Ḣ         # Remove first  item
  +        # Vectorised addition to original
   Ṫ       # Remove last item
    ₀%     # For each item, modulo 10
       ↔   # Repeat on input while output is truthy
        vṄ # Foreach, join by spaces
           # (C flag) Center and join by newlines.

```

-6 thanks to Aaron Miller.

Old version, 16 bytes:

```
L(ðn*₴DṄ,0p+vtḢṪ

```

Try it Online!

```
L(               # Length times
  ðn*            # (iteration number) spaces
     ₴           # Output without a newline
      D          # Triple current array
       Ṅ,        # Output first joined by spaces
         0p      # Prepend a 0 to the second
           +     # Vectorised addition
            vt   # Foreach, get last digit
              ḢṪ # And get rid of first + last items

```

# Answer
> 1 votes
# 05AB1E, 11 bytes

A translation of Adnan's answer to modern 05AB1E.

```
vT%DðýNú,ü+

```

Try it online!

`ú` pads a string with a given number of spaces and `ü` applies a binary function between pairs of adjacent items.

# Answer
> 1 votes
# PowerShell Core, ~~99~~ 69 bytes

```
($a=$args)|%{"$s$a"
$a=$a|%{($p+$_)%10;$p=$_}|select -skip 1
$s+=" "}

```

Try it online!

*-99 bytes thanks to @mazzy !*

# Answer
> 1 votes
# Jelly, 14 bytes

```
SƝƬ%⁵µ⁶oṚżK€ṖY

```

Try it online!

Full program which prints the result

## How it works

```
SƝƬ%⁵µ⁶oṚżK€ṖY - Main link. Takes a list L on the left
  Ƭ            - Until reaching a fixed point:
S              -   Take the sum of:
 Ɲ             -     All overlapping pairs
   %⁵          - Mod each by 10
     µ         - Begin a new link with the list of steps as the argument:
      ⁶o       - Replace all elements with spaces
        Ṛ      - Reverse
          K€   - Join each list with spaces
         ż     - Zip together
            Ṗ  - Remove the last line of spaces
             Y - Join on newlines

```

# Answer
> 0 votes
## C, 138 bytes

Golfed

```
c,d;main(int a,char**b){b++;while(c++,d=0,--a)while(d<a)printf("%*c%c",!d?c:1,*b[d],(d+2>a)*10),++d<a?*b[d-1]=(*b[d-1]+*b[d]-96)%10+48:0;}

```

Ungolfed

```
c,d;
main(int a,char**b){
b++;
while(c++,d=0,--a)
    while(d<a)
        printf("%*c%c",
          !d?c:1,      //number of blanks in front of digit
          *b[d],       //digit
          (d+2>a)*10), //returns 10(new line) only for d+1 == a
        ++d<a
          ? *b[d-1]=(*b[d-1]+*b[d]-96)%10+48 //update digit
          :  0;
}

```

# Answer
> 0 votes
## C#, 167 bytes

Im actually pretty proud of this solution, lambda expressions are so fun once you get the hang of them

```
void f(List<int> a){int x=a.Count;for(int s=0;s<x;s++){Console.WriteLine(new String(' ',s)+string.Join(" ",a));a=a.Take(x-s-1).Select((v,i)=>(a[i+1]+v)%10).ToList();}}

```

here ungolfed for further improvements:

```
void f(List<int> a)
{
int x = a.Count;
for (int s = 0; s<x ;s++)
{
    Console.WriteLine(new String(' ',s)+string.Join(" ",a));
    a=a.Take(x-s-1).Select((v,i)=>(a[i+1]+v)%10).ToList();
}
}

```

try it out here

# Answer
> 0 votes
# Python 3, 97 bytes

```
def f(x):print(*x);x[-1]==''or f(['']+[(x[i]+x[i+1])%10if''!=x[i]else''for i in range(len(x)-1)])

```

Prints a single trailing newline.

**How it works**

```
def f(x):                            function with input of list of numbers
print(*x)                            print the old line of the triangle
x[-1]==''or...                       if no more numbers, stop...
(x[i]+x[i+1])%10if''!=x[i]else''...  ...else compute the next entry in the new line if
                                     possible...
...for i in range(len(x)-1)          ...for all relevant digit pairs...
['']+...                             ...concatenate with empty string to force new leading
                                     space...
f(...)                               ...and pass to function

```

Try it on Ideone

# Answer
> 0 votes
# Haskell, 139 bytes

```
f=mapM(\(r,s)->putStrLn$r++(s>>=(++" ").show)).zip(iterate(' ':)"").takeWhile(/=[]).iterate g where g(_:[])=[];g(y:p:ys)=mod(y+p)10:g(p:ys)

```

Takes input as an argument, outputs to STDOUT.

Ungolfed version:

```
f = mapM (\(r, s) -> putStrLn $ r ++ (s >>= (++ " ") . show))
    . zip (iterate (' ' :) "")
    . takeWhile (/= [])
    . iterate sumTerms
    where sumTerms (_:[]) = []
          sumTerms (y:p:ys) = mod (y+p) 10 : sumTerms (p:ys)

```

# Answer
> 0 votes
# J, 44 bytes

```
(#\.-#)|."_1#\.(":@{."_1)2(10|+/)\^:(]i.@#)]

```

Based on this solution.

# Answer
> 0 votes
## Javascript (using external library) (198 bytes)

```
n=>{a=_.From(n);b=a.Write(" ");c=1;while(++c){a=a.BatchAccumulate(2).Where(y=>y.Count()==2).Select(z=>z.Sum()%10);if(a.Count()==0){break;}b+="\r\n"+_.Range(0,c).Write(" ",x=>"")+a.Write(" ")}return b}

```

Link to lib: https://github.com/mvegh1/Enumerable/

Code explanation: This was easy using the library! Doesn't win in bytes, but the code isn't too verbose and easy to read. So, the input "n' is an array of integers. Load it up into the library, stored in variable "a". "b" is the return string, store the joined string with " " as delimiter into b. c is the current iteration, use this to determine the number of spaces to insert. NOTE: This only seems to work nicely when the input is from 0-9. Then, while true, repeat a certain set of code. That code is to create adjacent batch sets of the current enumerable "a", i.e if we have \[1,2,3,4,5,6\] we get \[1,2\],\[2,3\],\[3,4\],...\[6\] ... then filter that so we only have the batches of size 2. Then we map that to a collection of the sums of the batches % 10. If a is empty, we are done, else we add the new line to our return. Finally return...

Picture coming in a few min.

# Answer
> 0 votes
# Japt `-R`, 16 bytes

```
_ä+ muA}hUÊN m¸û

```

Try it

```
_ä+ m%A}hNUÊ m¸û     :Implicit input of array U
_                    :Function taking an array as input
 ä                   :  Consecutive pairs
  +                  :  Reduced by addition
    m                :  Map
     %A              :    Mod 10
       }             :End function
        h            :Run that function
         N           :  Taking the last element of the array of all inputs, and pushing the results to it
          UÊ         :  Until it's length matches the length of U
             m       :Map the final N
              ¸      :   Join with spaces
               û     :Centre pad each with spaces to the length of the longest
                     :Implicit out put joined with newlines

```

# Answer
> 0 votes
# Stax, 14 bytes

```
üε↕Φ¬ⁿ╣VU6Co'm

```

Run and debug it

# Answer
> 0 votes
# Zsh, ~~99~~ 80 bytes

```
a=($@)
for j;{<<<$s$a;for i ({2..$#a})b+=($[(a[i-1]+a[i])%10])
s+=\ ;a=($b);b=;}

```

try it online! ~~<sub>99 bytes</sub>~~

# Answer
> 0 votes
# Java (JDK), ~~170~~ ~~165~~ 160 bytes

```
a->{int i=0,k,j,o=a.length;for(;i++<o;a[o-i]=-1){var s=" ".repeat(i);for(j=0;j<=o-i;)s+=a[j++]+" ";for(k=0;k<o-1;)a[k]=(a[k]+a[++k])%10;System.out.println(s);}}

```

Try it online!

Thanks to ceilingcat

# Answer
> 0 votes
# Pip `-s`, 20 bytes

```
Wg&OlPBxg:_+BMP Pg%t

```

Takes the numbers as command-line arguments. Try it online!

### Explanation

We'll be leaning heavily on the `-s` flag, which sets the list output format to "join on spaces." A list of three integers `[1 2 3]` is printed as `1 2 3`; a list of three empty strings `["" "" ""]` is printed as  (two spaces).

```
Wg&OlPBxg:_+BMP Pg%t
                      g is list of cmdline args; l is []; x is ""; t is 10 (implicit)
Wg                    While g is truthy (nonempty)
  &                   and the following is also truthy...
    lPBx              Append the empty string to l in-place
   O                  and output l (joined on spaces) with no trailing newline
                      The shenanigans with l 1) output 0, 1, 2, etc. spaces at the start of
                      each iteration, and 2) always evaluate as truthy (non-empty list),
                      thereby not affecting the while loop condition
                      Inside the loop:
                 g%t    Take each value in g, mod 10
                P       Print that list (joined on spaces) with a trailing newline
             MP         To each pair of numbers in the list, map this function:
          _               The first number
           +B             plus the second number
        g:              Assign that result back to g

```

---
Tags: code-golf, math, ascii-art, number, arithmetic
---


title: One hundred passwords

text:
# Question
Title: One hundred passwords
I have one hundred vaults, each one within another. Each vault has a password, consisting of a single number.

> 95 43 81 89 56 89 57 67 7 45 34 34 78 88 14 40 81 23 26 78 46 8 96 11 28 3 74 6 23 89 54 37 6 99 45 1 45 87 80 12 92 20 49 72 9 92 15 76 13 3 5 32 96 87 38 87 31 10 34 8 57 73 59 33 72 95 80 84 11 4 11 11 37 71 77 91 49 21 52 48 43 11 77 52 64 3 9 21 38 65 69 84 96 78 7 71 80 78 3 97

It's too hard to memorize all these passwords, and it's not safe to keep the passwords on a piece of paper. The only solution I can think of is to use a program with exactly one hundred characters. The password to the `n`th vault will be found by treating the first `n` characters of the code as a program.

Thus, the first character of the program, if run as a program by itself, must output `95`. The first two characters by themselves must output `43`. The entire program must output `97`.

I admit that this is really hard. So just do your best. **Try to make your program work for as many vaults as possible**, and I'll memorize the passwords to the rest.

## Rules

* If there is a tie, the winner is the earliest submission.
* Standard loopholes forbidden. That includes reading from other files or from the Internet.
* You have a few options for the code:
    + A full program which prints the correct number
    + A function which returns or prints it
    + An expression which evaluates to it (e.g. in C, `4+3` evaluates to `7`)
* You *may* assume a REPL environment
* You *may* use different techniques for each value of `n`. For example, you can use different languages for each `n`, or sometimes use a full program and sometimes a function.

*Note: This scenario is completely fictional. If you have a similar issue, do not post your passwords online.*

# Answer
> 28 votes
# \>\<\> (Fish), 95

Starting after the `'` puts all characters onto the stack and at the end of the line it wraps around; closes the string with the same `'`; outputs the top of the stack as a number (`n`) and finish execution (`;`).

Characters for 13 and 10 were changed to space to not ruin the layout of the code (as fish is a 2D language.)

Some non-printable ASCII disappears in the answer. Correct program here.

```
'n;Y8Y9C-""NX(QN.`JY6%c--WP\1H  \LX `W&WX"9I;!H_PT%GM[140+M4@   &AET`NGPNa

```

Thanks for Martin Büttner and Sp3000 for improvements of 2 and 5 bytes.

Hex dump:

```
0000000: 276e 3b59 3859 3943 072d 2222 4e58 0e28  'n;Y8Y9C.-""NX.(
0000010: 5117 1a4e 2e08 600b 1c03 4a06 1759 3625  Q..N..`...J..Y6%
0000020: 0663 2d01 2d57 500c 5c14 3148 095c 0f4c  .c-.-WP.\.1H.\.L
0000030: 5803 0520 6057 2657 1f58 2208 3949 3b21  X.. `W&W.X".9I;!
0000040: 485f 5054 0b04 0b0b 2547 4d5b 3115 3430  H_PT....%GM[1.40
0000050: 2b0b 4d34 4003 0915 2641 4554 604e 0747  +.M4@...&AET`N.G
0000060: 504e 0361                                PN.a

```

# Answer
> 11 votes
# CJam, 40

I just used a greedy approach (most of the time) to print the next possible number (carets mark correct program ends):

```
43;56) ; 34 K- 9+ 2* ;11;3Z+;54;6;1 ;80C+K- K+G-;32 6+ 7-Z+;73(  ; 11  60+K+;52;11;64;9;65;7 8;1;8
 ^  ^ ^   ^^  ^  ^  ^  ^ ^ ^  ^ ^  ^  ^ ^  ^ ^ ^ ^ ^  ^ ^ ^  ^  ^   ^ ^^ ^ ^  ^  ^  ^ ^  ^   ^^^ ^

```

The following numbers are printed correctly:

> 95 **43** 81 89 **56** 89 **57** 67 7 45 **34** **34** 78 88 **14** 40 81 **23** 26 78 **46** 8 96 **11** 28 **3** 74 **6** 23 89 **54** 37 **6** 99 45 **1** 45 87 **80** 12 **92** 20 49 **72** 9 **92** 15 **76** 13 **3** 5 **32** 96 87 **38** 87 **31** 10 **34** 8 57 **73** 59 33 **72** 95 80 84 **11** 4 **11** **11** 37 **71** 77 **91** 49 21 **52** 48 43 **11** 77 52 **64** 3 **9** 21 38 **65** 69 84 96 **78** **7** **71** 80 **78** 3 97

Test it here.

# Answer
> 8 votes
# CJam, 56

Here is a somewhat more elaborate approach. It prints the last 56 numbers correctly:

```
0{;"箪⇓ⲩ䏨攛믹Ğᅏꛥ훻ᆾ㼖ꦅ땶읥湓ᠤ䡶"2G#b99bW):W=}:F;FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

```

Chances are, SE has swallowed some characters, so here's a pastebin. You can try the code here.

It makes use of the fact, that the challenge asks for the programs in characters, so I'm using Unicode characters to encode the last 56 characters in a function, which then leaves the correct element on the stack by incrementing a variable on each invocation and selecting the corresponding element. The rest of the code just calls the function repeatedly.

The first correct program is the one ending at the second `F` in the code. I've fiddled around with the length of characters to be encoded for a while until I hit the right balance to make as much use as possible. One or two more might be possible with this approach.

# Answer
> 8 votes
# (vintage) C - 88

*No need for all these silly dedicated golfing languages. Better go back to the good old days, before the quiche eaters and their "program = algorithm+data" nonsense ruined all the fun.*

The code is a C function, stored as a string.
It returns the binary value as an integer.

Run it in DosBox with Borland Turbo C 2.0.
There are no control characters in the string, so a copy-paste should work.
Compile with **`tiny`** memory model or else...

```
typedef int (* pfun)();
main ()
{
    pfun passwd = (pfun) "¬< sûŠDþ,#ÃEq{1Kt:=qQ+ƒ.?&m):|YH)†P$Pzs/7Tk,2o0&(CƒzIzB-E+\l^Dk‚sw.'..Hjp~T8WSN.pWc&,8Idhwƒq*jsq&„";

    printf ("password %d\n", passwd());
}

```

If you disassemble the start of the string, you'll see something like:

```
scan: lodsb
      cmp al,32
      jae scan
      mov al,[si-2]
      sub al, 35
      ret

```

since `si` is used as function address, it points directly to the code, followed by the passwords.

All values are shifted by 35 to avoid escaping control characters and double quotes.

The code is 11 bytes long, so it will work up to 12 characters.

Unfortunately, the 11th value (34) is too low to produce a valid password with an increased shift value (`ret` opcode is 195, so you would need a shift of 161, and the maximal shift to avoid a rollover is 255-99=156).

11 characters will produce a wrong value, and your virtual PC will experience severe (and usually lethal) undefined behaviours with 10 characters or less.

# Answer
> 7 votes
# Pyth, ~~92~~ 93

```
+_32Ce"c'MBBnx.Hq7:nN(+<#j&7yVE&M!Mwp,|4Qh)|/l-#%@wFw?*B(Yi[Ahpt+$++Egm{Q5TPK+mT`#)5Faetn'gpn#

```

The above code will obviously be messed up because SE removes control characters, so find the actual code here

The logic is simple, the string is the character representation of each number, except for the first 3 which are used by the conversion logic and some quotes and newlines which I replaced with dummy characters.

I will try to increase the score here.

Try it online here

# Answer
> 6 votes
# Matlab ~~37~~ 39

You can use part (without the semicolons) of this idea with any programming language you like, that prints the results directly to console. This will produce at least 39 times the right answers. (I did not check those where only a half number might give a correct answer, but I've found two so far.)

```
43+13+11-33+54;81;78;8+20;74+15-83;01+79-59-12+6-2;;87+0-53+39;72;;11+00+66-56+22;52;3*7+48;78-7+7+0

```

# Answer
> 1 votes
# Python 3, Score 71

```
sum(*open(__file__,'br'))%112#M_Q]:D,*i,P(1S#=1fr@g?18[V1bV'at'iwp"v~FTlkPBW|3v|t|^)@yn%^

```

Try it online!

Note: the code contains unprintable char

Read the code source, and sum all the char value modulo 112 (to include the comment sign `#`. Then adjust each value with the right char in a comment

# Answer
> 0 votes
# Python 2, 39

I wrote a script that tries lots of combinations of expressions, and tests them against the safe combinations. The best I could manage was 39 matches. I was surprised how many combinations resulted in the score of 39. I have included a sample in my answer.

I tried including the logical `^&|` operators but the precedence rules got complicated.

```
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+33+54-39-41*0-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60-11+67-71+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2+19 +6-7+3+39 -1+12-73 +66-56+22 +9-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3+63/5+14 +8+0-33+8-11+67-71+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11+67-71+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11/2-2+19 +6-7+3+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48+45-54-33+8-11/2-2*5+82+0-53+39 -1+12-73 +66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48+45-54-33+8-11/2-2+19 +6-7+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35-8+3+48+45-54-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11+67-71+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48+45-54-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60/7-57-2*5+82-56+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11/2-2+19 +6-7+3+39 -1+12-73 +66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11+67-71+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2+19 +6-7+3+39 -1+12-73 +66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11+67-71+82-56+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11+67-71+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48+45-54-33+8-11+67-71+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82-56-23+51+36-84+00+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11+67-71+82+0-53+39 -1+8-76+33+54-39-41*0-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2+19 +6-7+3+39 -1+12-73+60-22+3-41*0-43/3+46-6 +2+17
43+13+11-33+54 -7 -35-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+33+54-39-41*0-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2+19 +6-28+47+2+36-84+00+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11+67-71+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2+19 +6-28-2+51+36-84+00+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7-681
43+13+11-33+54 -7 -35-35-8+3+48*0 -5+79-60-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33+54 -7 -35-35-8+20+14 +8+0-33+8-11/2-2+19 +6-7+3+39 -1+12-73 +66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2+19 +6-28-2+51+36-84+00+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11/2-2*5+82-56+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+12-73+60-22+3-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11/2-2*5+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2+19 +6-7+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48+45-54-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82-56+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11+67-71+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82-56+3+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7-681
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82-56-23+51+36-84+0+60-22+3-9 +9-43/3+46-6-7-681
43+13+11-33+54/8-14-18+3-8+20+14 +8+0-33+8-11/2-2*5+82-56+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48+45-54-33+8-11/2-2+19 +6-7+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48+45-54-33+8-11/2-2+19 +6-28-2+51+36-84+0+60-22+3-41*0-43/3+46-6-7*011
43+13+11-33+54 -7 -35-35-8+20+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11/2-2*5+82-56+3+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60-11/2-2*5+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35-8+3+48+45-54-33+8-11/2-2*5+82-56+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60/7-57-2*5+82-56-23+51+36-84+00+66-56+22 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2+19 +6-7-23+51+36-84+00+66-56+22 +9-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60-11/2-2+19 +6-7+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11+67-71+82-56+3+39 -1+12-73 +66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11/2-2*5+82-56-23+51+36-84+00+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11/2-2*5+82+0-53+39 -1+12-73 +66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11/2-2*5+82-56+3+39 -1+12-73 +66-56+22 +9-43/3+46-6-7-681
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60/7-57-2+19 +6-7+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11/2-2+19 +6-7+3+39 -1+8-76+33+54-39-41*0-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+12-73+60-22+3-41*0-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11/2-2+19 +6-7-23+51+36-84+00+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+33+54-39-41*0-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2+19 +6-7+3+39 -1+8-76+33+54-39-41*0-43/3+46-6-7-681
43+13+11-33+54 -7 -35-35-8+3+48*0 -5+79-60/7-57-2+19 +6-7+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+12-73+60-22+3-9 +9-43/3+46-6-7*011
43+13+11-33+54 -7 -35-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82-56-23+51+36-84+0+60-22+3-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+12-73 +66-56+22 +9-43/3+46-6 +2+17
43+13+11-33+54/8-14-18+3-8+3+48+45-54-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11+67-71+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3-8+20+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11+67-71+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11+67-71+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48+45-54-33+8-11/2-2*5+82-56-23+51+36-84+0+60-22+3-9 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+12-73 +66-56+22 +9-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3+63/5+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+12-73 +66-56+22 +9-43/3+46-6 +2+17
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11/2-2+19 +6-7+3+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60-11/2-2+19 +6-7+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+12-73+60-22+3-9 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11/2-2+19 +6-7+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+20+14 +8+0-33+8-11+67-71+82+0-53+39 -1+12-73 +66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11+67-71+82+0-53+39 -1+12-73 +66-56+22 +9-43/3+46-6-7*011
43+13+11-33+54 -7 -35-35+63/5+14 +8+0-33+8-11/2-2*5+82-56-23+51+36-84+00+66-56+22 +9-43/3+46-6 +2+17
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+12-73+60-22+3-9 +9-43/3+46-6 +2+17
43+13+11-33+54/8-14-18+3-8+3+48+45-54-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+12-73 +66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82-56+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2*5+82-56+3+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3+63/5+14 +8+0-33+8-11/2-2*5+82-56+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7-681
43+13+11-33 -20 +9+23-35+63/5+14 +8+0-33+8-11/2-2*5+82+0-53+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3-8+3+48*0 -5+79-60/7-57-2*5+82+0-53+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011
43+13+11-33+54/8-14-18+3+63/5+14 +8+0-33+8-11/2-2+19 +6-7+3+39 -1+8-76+7+66-56+22 +9-43/3+46-6-7*011
43+13+11-33 -20 +9+23-35-8+3+48*0 -5+79-60/7-57-2+19 +6-7+3+39 -1+8-76+33+54-39-9 +9-43/3+46-6-7*011

```

# Answer
> 0 votes
# DEBUG.COM, 93

```
0000h: BE FF 00 01 CE AC CC 67 07 45 34 34 78 88 14 40
0010h: 81 23 26 78 46 08 96 11 28 03 74 06 23 89 54 37
0020h: 06 99 45 01 45 87 80 12 92 20 49 72 09 92 15 76
0030h: 13 03 05 32 96 87 38 87 31 10 34 08 57 73 59 33
0040h: 72 95 80 84 11 04 11 11 37 71 77 91 49 21 52 48
0050h: 43 11 77 52 64 03 09 21 38 65 69 84 96 78 07 71
0060h: 80 78 03 97

```

Usage:

```
DEBUG.COM FILENAME.COM
G

```

and the result appears in `AL`

---
Tags: code-challenge, kolmogorov-complexity, source-layout
---