# Print number triangle

Given a number N, output a NxN right angled triangle, where each row i is filled with numbers up to i.

Example

n = 0

(no output)

n = 4

1
1 2
1 2 3
1 2 3 4


n = 10

1
1 2
1 2 3
.
.
.
1 2 3 4 5 6 7 8 9 10


(no alignment needed)

n = N

1
1 2
1 2 3
.
.
.
1 2 3 4 .... N


There is no trailing space at the end of each line.

Least number of bytes wins, and standard loopholes are not allowed.

• Can the output be a nested list of numbers? – seequ Mar 12 '15 at 5:39
• What should be the behavior for n=0, and for n>9? – freekvd Mar 12 '15 at 18:55
• @Sieg Sure, as long as the output is correct. – Tan WS Mar 13 '15 at 0:57
• @freekvd for 0 there is no output, for n>9 no special formatting required – Tan WS Mar 13 '15 at 1:00
• Ah darn, you broke my submission. Fixing ASAP – seequ Mar 13 '15 at 5:54

## UniBasic 50 Bytes

S='';INPUT N;FOR I=1 TO N;S:=I;CRT S;S:=' ';NEXT I


Ungolfed:

S=''
INPUT N
FOR I=1 TO N
S:=I
CRT S
S:=' '
NEXT I


# awk, 27 bytes

{for(n=$0;n>=$i=++i;)print}


Got it working with some tweaks.

### Example usage and output

me@home:~$echo 0 | awk '{for(n=$0;n>=$i=++i;)print}' me@home:~$ echo 1 | awk '{for(n=$0;n>=$i=++i;)print}'
1
me@home:~$echo 2 | awk '{for(n=$0;n>=$i=++i;)print}' 1 1 2 me@home:~$ echo 12 | awk '{for(n=$0;n>=$i=++i;)print}'
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10 11 12


# q, 18 bytes

1+til each 1+til n


# MATLAB, 63

for m=1:input('');fprintf(['1' repmat(' %d',1,m-1) 10],2:m);end


Not the best, but because of the requirements on spaces, functions like num2str and disp can't be used as they produce too many.

Run the code and enter the number when prompted (~=STDIN). It will then print the number triangle.

# MATLAB, 38

@(n)spy(sparse(tril(repmat(1:n,n,1))))


This one is a bit of a wildcard answer. It doesn't print the output, but rather makes a pretty graph. I know this is probably outside the rules, if so refer to my other answer, but I thought I would post this one anyway as it looks quite cool :)

# JavaScript, 77 Bytes

function(n){for(i=1;i<=n;i++){a='';for(j=1;j<=i;j++)a+=j+' ';console.log(a)}}


# PowerShell -  42 32bytes

Edit: AdmBorkBork reports that we can save many bytes by using a complete script, and assuming a default delimiter!

 param($n)0..$n-gt0|%{"$(1..$_)"}


Never done any serious PowerShell, just felt I might learn something from this, and indeed I did. Old 42byte code:

function k($n){0..$n-gt0|%{1..$_-join" "}}  Defines a function k which takes an input $n, creates a range from 0 through to $n, filters for entires greater than 0, then creates a range from 1 to each remaining value, and joins these with a space. Example out: PS > k 3 1 1 2 1 2 3 PS > k 0 PS >  Alternatively, you can define a filter, which will print as many triangles as you want. filter z{0..$_-gt0|%{1..$_-join" "}} PS > 3,0,2|z 1 1 2 1 2 3 1 1 2 PS >  • Hiya! Not sure if you're still around, but you can use a full script instead of a function and use the default $OutputFieldSeparator to get down to 32 bytes with param($n)0..$n-gt0|%{"$(1..$_)"} -- Try it online! – AdmBorkBork Jan 20 '17 at 21:10
• @AdmBorkBork I do indeed still lurk around here, thanks for the tips! – VisualMelon Jan 20 '17 at 22:33

# Pushy, 4 bytes

Non-competing as the language postdates the challenge.

:Lh_


Try it online!

This works by building the stack up to the final line, step-by-step, and printing the stages:

:    \ Input times do (this consumes input):
Lh   \  Push stack length + 1
_    \  Print stack items, space separated.


# VBA, 116 bytes

Function n(m As Integer)
If m > 0 Then
For a = 1 To m
n = n & " " & a
Next
Debug.Print n(m - 1)
End If
End Function

• Doesn't this generate a leading new line and a leading space? – dwana Mar 13 '15 at 8:46
• oh leading space isn't allowed? I thought only trailing space is not allowed – Alex Mar 13 '15 at 14:22

# 05AB1E, 3 bytes

LL»


Try it online.

Explanation:

L      # Create a list in the range [1, (implicit) input]
L     # Map each integer i to a list in the range [1, i]
»    # Join the list of lists by newlines,
# which implicitly also joins the inner lists by a single space
# (and output it implicitly)