# Ascending integer pyramid

Output either the text below, or a list of lists of integers (more details below).

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


## Rules

• If you wish, you may "one index" and replace each n with n+1. In this case the output will contain the numbers 1 to 100 inclusive.

### If output is text

• The single digits are right aligned in each column in the text provided, but it is fine if you wish to left align. Additionally, alignment is not required to be consistent between columns.
• Leading/trailing whitespace is permitted. Trailing spaces on each line are also permitted.
• Returning a list of lines is acceptable.

### If output is numerical

• Output can be a list of lists of integers (or 2D array): [[1], [11, 2], [21...
• Floats are fine.
• If it is not possible to have nonrectangular array in the language used, then the elements in the array that aren't within the triangle can take any value and will be ignored.

If you prefer another format, feel free to ask.

Shortest code wins.

• Sandbox – dylnan Apr 26 '18 at 17:30
• Since leading/trailing white-space is permitted in the textual output, are leading/trailing empty lists permitted in the list output? – Jonathan Allan Apr 26 '18 at 21:45
• @JonathanAllan Sure – dylnan Apr 26 '18 at 21:46
• i cant edit it in, but this should have the kolmogorov complexity tag (not sure i spelled that right...) – Brian H. Apr 27 '18 at 12:04
• @BrianH. According to others, since there isn't really a single constant that is meant to be produced, the KC tag doesn't apply here – dylnan Apr 27 '18 at 15:01

# Jelly,  13 12 10  6 bytes

-4 thanks to Dennis, yes FOUR! (use of group indices and Cartesian product)

⁵pḅ1ĠU


Uses 1-indexing and the list option for output.

Try it online! (The footer formats the output in Python representation)
...or see a 0-indexed, formatted version.

### How?

⁵pḅ1ĠU - Main link: no arguments
⁵      - literal 10
p     - Cartesian product (with the leading constant of 10 and implicit ranges)
-       = [[1,1],[1,2],[1,3],...,[10,8],[10,9],[10,10]]
ḅ1   - to base one (proxy for sum each without the monad)
-       = [2,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,12,4,...,18,19,20]
Ġ  - group indices by value
-       = [[1],[2,11],[3,12,21],...,[90,99],[100]]
U - upend = [[1],[11,2],[21,12,3],...,[99,90],[100]]

• Nice. I had 7 bytes – dylnan Apr 26 '18 at 23:10
• What in the world does Ġ even do?! – Magic Octopus Urn Apr 27 '18 at 14:09
• @MagicOctopusUrn it groups the indices of an array by their corresponding value. So [5,7,5,9]Ġ would return [[1,3],[2],[4]]. This is because indices [1,3] correspond to value 5 in the original array, [2] to 7 and [4] to 9. – dylnan Apr 27 '18 at 16:48

# Python 2, 54 bytes

k=1
exec"print range(k,0,-9)[:101-k];k+=10-k/91*9;"*19


Try it online!

(1-indexed, because range(k,0,-9) is shorter than range(k,-1,-9).)

# Charcoal, 29 20 bytes

Ｅ¹⁹⪫Ｉ⮌Φ¹⁰⁰⁼ι⁺÷λχ﹪λχ


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

 ¹⁹                     Literal 19
Ｅ                       Map over implicit range
¹⁰⁰              Literal 100
Φ                 Filter over implicit range
λ  λ      Inner index
χ  χ     Predefined variable 10
﹪       Modulo
÷          Integer divide
⁺           Sum
ι            Outer index
⁼             Equals
⮌                  Reverse
Ｉ                   Cast to string
⪫                    Join with spaces
Implicitly print each string on its own line


# JavaScript (ES6), 61 bytes

0-based. Returns a string.

f=(k=n=0)=>k>98?k:k+((k-=9)%10>0?' '+f(k):
+f(n+=n>89||10))


Try it online!

### How?

We start with k = n = 0 and stop when k = 99. We subtract 9 from k at each iteration.

End of rows are detected with k % 10 <= 0. This condition is fulfilled if:

• k is negative (upper part of the pyramid) because the sign of the modulo in JS is that of the dividend.

 0 (-9)
10  1 (-8)
20 11  2 (-7)

• or k % 10 == 0 (lower part of the pyramid)

90 81 72 63 54 45 36 27 18  9 (0)
91 82 73 64 55 46 37 28 19 (10)
92 83 74 65 56 47 38 29 (20)


At the beginning of the next row, we add either 1 or 10 to n and restart from there.

# Python 2, 66 bytes

r=range
for a in r(0,90,10)+r(90,100):print r(a,a/10+a%10*10-1,-9)


Try it online!

# J, 14 bytes

,.<@|./.i.,~10


Try it online!

## Note:

This solution uses boxed output - I'm not sure if it's allowed (I hope it is, because lists of integers are also allowed)

# J, 10 bytes

|./.i.,~10


In this solution the numbers outside the triangular area are displayed as 0

Try it online!

## Explanation:

i.,~10 creates a matrix 10x10 of the numbers 0..99 ,~10 is short for 10 10

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


/. finds the oblique diagonals (antidiagonals) of the matrix

   ]/.i.,~10
0  0  0  0  0  0  0  0  0  0
1 10  0  0  0  0  0  0  0  0
2 11 20  0  0  0  0  0  0  0
3 12 21 30  0  0  0  0  0  0
4 13 22 31 40  0  0  0  0  0
5 14 23 32 41 50  0  0  0  0
6 15 24 33 42 51 60  0  0  0
7 16 25 34 43 52 61 70  0  0
8 17 26 35 44 53 62 71 80  0
9 18 27 36 45 54 63 72 81 90
19 28 37 46 55 64 73 82 91  0
29 38 47 56 65 74 83 92  0  0
39 48 57 66 75 84 93  0  0  0
49 58 67 76 85 94  0  0  0  0
59 68 77 86 95  0  0  0  0  0
69 78 87 96  0  0  0  0  0  0
79 88 97  0  0  0  0  0  0  0
89 98  0  0  0  0  0  0  0  0
99  0  0  0  0  0  0  0  0  0


Using ] (same) pads all lines with 0s. Each line is reversed. In order to get rid of the zeroes I box the lines < after they are reversed |.

   <@|./.i.,~10
┌─┬────┬───────┬──────────┬─────────────┬────────────────┬
│0│10 1│20 11 2│30 21 12 3│40 31 22 13 4│50 41 32 23 14 5│. . .
└─┴────┴───────┴──────────┴─────────────┴────────────────┴


Boxing makes the list of lists to be flatten. I finally ravel ,. the list so that the lines are ordered in a column.

  ,.<@|./.i.,~10
┌────────────────────────────┐
│0                           │
├────────────────────────────┤
│10 1                        │
├────────────────────────────┤
│20 11 2                     │
├────────────────────────────┤
│30 21 12 3                  │
├────────────────────────────┤
│40 31 22 13 4               │
├────────────────────────────┤
│50 41 32 23 14 5            │
├────────────────────────────┤
│60 51 42 33 24 15 6         │
├────────────────────────────┤
│70 61 52 43 34 25 16 7      │
├────────────────────────────┤
│80 71 62 53 44 35 26 17 8   │
├────────────────────────────┤
│90 81 72 63 54 45 36 27 18 9│
├────────────────────────────┤
│91 82 73 64 55 46 37 28 19  │
├────────────────────────────┤
│92 83 74 65 56 47 38 29     │
├────────────────────────────┤
│93 84 75 66 57 48 39        │
├────────────────────────────┤
│94 85 76 67 58 49           │
├────────────────────────────┤
│95 86 77 68 59              │
├────────────────────────────┤
│96 87 78 69                 │
├────────────────────────────┤
│97 88 79                    │
├────────────────────────────┤
│98 89                       │
├────────────────────────────┤
│99                          │
└────────────────────────────┘


# Pure Bash (no external utilities), 66

eval a={{9..1},}\;b={9..0}';c[a+b]+=$a$b\ '
printf %s\\n "${c[@]}"  Try it online! # Pyth, 16 bytes V19fqssMTN_U100  Try it online! • – Mr. Xcoder Apr 27 '18 at 4:24 # Gol><>, 24 bytes 0D9FlF{a+|lD|9F~lF{P|D|;  Try it online! The output looks like this: [0] [10 1] [20 11 2] [30 21 12 3] [40 31 22 13 4] [50 41 32 23 14 5] [60 51 42 33 24 15 6] [70 61 52 43 34 25 16 7] [80 71 62 53 44 35 26 17 8] [90 81 72 63 54 45 36 27 18 9] [91 82 73 64 55 46 37 28 19] [92 83 74 65 56 47 38 29] [93 84 75 66 57 48 39] [94 85 76 67 58 49] [95 86 77 68 59] [96 87 78 69] [97 88 79] [98 89] [99]  ### How it works 0D9FlF{a+|lD|9F~lF{P|D|; 0D Push 0 and print stack 9F | Repeat 9 times... lF{a+| Add 10 to all numbers on the stack l Push stack length (the last one-digit number) D Print stack 9F | Repeat 9 times... ~ Discard the top lF{P| Increment all numbers on the stack D Print stack ; Halt  # R, 50 48 bytes split(y<-rev(order(x<-outer(0:9,0:9,"+"))),x[y])  Try it online! 1-indexed. Follows the same logic as Jonathan Allan's Jelly answer, so make sure to upvote him. As a bonus, here is also an implementation of standard looping approach (0-indexed). Here, I at least tried to make the output prettier (thus, didn't even save bytes for print instead of cat(...,"\n") to get rid of annoying [1]s in the console. # R, 66 59 bytes for(i in c(0:8*10,90:99))cat(seq(i,i/10+i%%10*10-1,-9)," ")  Try it online! Edit: -2 and -7 both thanks to Giuseppe. • I managed to golf down the second one to 59 bytes and the first to 48 bytes – Giuseppe Apr 27 '18 at 16:16 • Ah, yes, thanks. – Kirill L. Apr 27 '18 at 17:02 • @KirillL.It's always realy elegant to use outer. plus in this case it's shorter! – JayCe Apr 27 '18 at 19:26 # R, 137 86 73 69 bytes for(u in 0:18)cat("if"(u>9,seq(81+u,10*u-81,-9),seq(10*u,u,-9)),"\n")  Try it online! Previous golfed version, %100 credits to Giuseppe. S=sapply c(S(1:10,function(u)1:u-1+10*(u-1:u)),S(9:1,function(y)1:y+9-y+10*(y:1+9-y)))  Try it online! Below my first attempt at Codegolf keeping it just for the record. x<-c(1:10) z<- c(9:1) c(sapply(x,function(u) seq_len(u)-1+10*(u-seq_len(u))),sapply(z,function(y) seq_len(y)+9-y+10*rev(seq_len(y)+9-y)))  Try it online! • Nice answer! Like you say, you can remove quite a few bytes; I've managed to find an 86 byte solution by removing some unnecessary white-space, and replacing seq_len with 1: in most places; I also used y:1 instead of rev. – Giuseppe Apr 26 '18 at 20:40 • @Giuseppe many thanks for the improved answer - it shows that I haven't coded in years. – JayCe Apr 26 '18 at 22:24 # Octave, 676665 64 bytes for i=0:8disp(10*i:-9:0)end,for i=0:9disp(90+i:-9:11*i+(i<1))end  Try it online! Those missing semicolons hurt my eyes! # 05AB1E, 22 bytes TLûvTLD>T*«NèyGD9+})R,  Try it online! Super Naive Approach: Try it online! may be a better solution but I can't figure out how to get from A to B. • Is there a "sort a based on values of b" command? – dylnan Apr 27 '18 at 18:47 # PowerShell, 77 bytes (0..90|?{!($_%10)})+91..99|%{"$(for($i=$_;$i-gt$_/10+$_%10*10-1;$i-=9){$i})"}


Try it online!

Outputs as ASCII-art with the single-digits left-aligned. Exploits the fact that stringifying an array inserts spaces between elements by default.

Very similar to Rod's Python answer, apparently, but developed independently.

# JavaScript, 69 bytes

f=(i=e=[])=>e[i<19&&(e[+i]=[]),i/10+i%10|0].unshift(+i)*i++-99?f(i):e


Try it online!

# JavaScript REPL, 77 bytes

[...Array(100)].map((_,i)=>e[i<19&&(e[i]=[]),i/10+i%10|0].unshift(i),e=[])&&e


# Perl 5, 62 bytes

$,=$";say@,=map$_+=10,@,,$_ for-9..0;say map++$_,@,while pop@,  Try it online! 1-indexed to save a couple bytes # Ruby, 58 bytes 0.step(180,10){|x|p x.step(0,-9).select{|y|y<100&&y>x-90}}  Try it online! # Red, 105, 95 91 bytes v: make vector! 0 loop 10[alter v + 10 length? v print v]loop 9[alter v last v print 1 + v]  Try it online! ## Explanation: v: make vector! 0 ; start with a vector with one element: -10 loop 10[alter v + 10 length? v print v] ; Ten times print the vector after adding 10 ; to its elements and appending the length loop 9[alter v last v print 1 + v] ; Nine times print the vector after adding 1 ; to its elements and removing the last one ; alter appends the item if it's not ; in the list, otherwise removes it  # JavaScript, 112 bytes Not that optimal, but I wanted to try a different approach. [...Array(19)].map((x,y)=>y>9?81+y:y?y+'0':y).map(x=>(f=(n,a=[n])=>!n|a[n+='']|n[1]>8?a:f(n-=9,a.concat(n)))(x))  Try it online! Old Solution: [...Array(19)].map((x,y)=>y>9?y-9+'9':y).map((x,y)=>(f=(n,a=[n])=>a[n/10]|!n?a.reverse():a.push(n+=9)&&f(n,a))(x*1).slice(y-19))  Try it online! # 05AB1E, 16 bytes тL<ΣTLãOsè}TLû£í  Try it online! Explanation тL<Σ } # sort the values in [0 ... 99] by sè # the value at that index in O # the sum of ã # the cartesian product of TL # the range [1 ... 10] £ # split the result into pieces of sizes TLû # [1,2,...,9,10,9,...2,1] í # and reverse each  # Perl 6, 43 40 bytes {map {[R,] grep :k,$_,(^10 X+ ^10)},^19}


Try it online!

-3 bytes thanks to Brad Gilbert b2gills.

• [R,] LIST is shorter than reverse LIST` – Brad Gilbert b2gills May 1 '18 at 1:19
• @BradGilbertb2gills Nice, thanks! – nwellnhof May 1 '18 at 13:52