| Bytes | Lang | Time | Link |
|---|---|---|---|
| 003 | Vyxal 3 | 250819T080555Z | lyxal |
| 006 | APLNARS | 250819T075653Z | Rosario |
| 014 | tinylisp 2 | 230201T181348Z | DLosc |
| 044 | Swift 5.9 | 240312T155737Z | macOSist |
| 013 | Juby | 230614T151609Z | Jordan |
| 007 | Uiua SBCS | 240312T153508Z | chunes |
| 007 | Pip p | 240312T051746Z | DLosc |
| 003 | Thunno 2 | 230622T175105Z | The Thon |
| 020 | Wolfram Language Mathematica | 200211T144010Z | ZaMoC |
| 018 | Arturo | 230129T123716Z | chunes |
| 004 | Nekomata | 230614T035751Z | alephalp |
| 021 | Julia 1.0 | 230202T180127Z | Ashlin H |
| 012 | Pip | 230202T155814Z | Baby_Boy |
| 042 | Swift 5.6+ | 230202T022115Z | Bbrk24 |
| 025 | FunStack alpha | 230201T212149Z | DLosc |
| 058 | Erlang | 230201T005510Z | Yuri Gin |
| 002 | Nibbles | 230130T230100Z | Adam |
| 003 | Vyxal | 230130T020136Z | lyxal |
| 060 | JavaScript | 230129T234105Z | EzioMerc |
| 046 | shell with seq loop | 230129T204538Z | gildux |
| 105 | Go | 230129T193924Z | bigyihsu |
| 045 | Elm | 230129T165405Z | Kirill L |
| 005 | Pyt | 230129T164916Z | Kip the |
| 010 | BQN | 230129T155857Z | Jacobus |
| 006 | Stax | 200220T181400Z | Nanajnai |
| 145 | TSQL | 200217T145947Z | t-clause |
| 008 | K ngn/k | 200212T154400Z | scrawl |
| 047 | Fortran GFortran | 200213T205241Z | DeathInc |
| 009 | Burlesque | 200213T204751Z | DeathInc |
| 029 | Coffeescript | 200213T195415Z | Penagwin |
| 022 | Zsh | 200213T153937Z | GammaFun |
| 098 | Java JDK | 200213T145826Z | Olivier |
| 037 | Kotlin | 200213T041843Z | snail_ |
| 010 | 200211T214401Z | SirBogma | |
| 042 | C gcc | 200212T192041Z | Digital |
| 027 | Haskell | 200213T010144Z | Curry Ba |
| 051 | Haskell | 200211T215015Z | Matthew |
| 012 | x8616 machine code | 200211T224605Z | 640KB |
| 036 | Clojure | 200212T103929Z | Kirill L |
| 004 | MathGolf | 200212T102034Z | Kevin Cr |
| 005 | Brachylog | 200212T100911Z | Fatalize |
| 011 | J | 200212T072940Z | Galen Iv |
| 003 | Jelly | 200211T143310Z | RGS |
| 013 | Raku | 200211T225212Z | Jo King |
| 020 | Retina | 200211T223226Z | Neil |
| 054 | PHP | 200211T163943Z | 640KB |
| 030 | Ruby | 200211T153340Z | G B |
| 049 | JavaScript ES6 | 200211T150845Z | Arnauld |
| 054 | PHP | 200211T204515Z | Guillerm |
| 019 | R | 200211T164703Z | Giuseppe |
| 045 | Factor | 200211T190009Z | Galen Iv |
| 054 | C gcc | 200211T184918Z | S.S. Ann |
| 009 | Charcoal | 200211T184901Z | Neil |
| 004 | Japt | 200211T181351Z | Shaggy |
| 015 | shell + sed | 200211T164957Z | user4180 |
| 004 | APL Dyalog Unicode | 200211T144414Z | Adá |
| 003 | 05AB1E | 200211T161535Z | Grimmy |
| 029 | Pure Bash no external utilities | 200211T161306Z | Digital |
| 046 | Python 3 | 200211T145611Z | Noodle9 |
| 1213 | GolfScript | 200211T153301Z | Mathgeek |
| 005 | Pyth | 200211T151513Z | Citty |
| 046 | Python 3 | 200211T150011Z | Jitse |
| 019 | PowerShell | 200211T144134Z | AdmBorkB |
APL(NARS), 6 chars
⌽¨⍳¨⍳⎕
input one number >0 output one list of list of numbers.
test:
⌽¨⍳¨⍳⎕
⎕:
4
┌4──────────────────────────────┐
│┌1─┐ ┌2───┐ ┌3─────┐ ┌4───────┐│
││ 1│ │ 2 1│ │ 3 2 1│ │ 4 3 2 1││
│└~─┘ └~───┘ └~─────┘ └~───────┘2
└∊──────────────────────────────┘
tinylisp 2, 14 bytes
(.(p m to1)1to
Explanation
(.(p m to1)1to)
(p ) ; Partially apply
m ; the map function
to1 ; to the to1 function (given N, return the list of numbers from
; N down to 1)
(. ) ; Compose that with
1to ; the 1to function (given N, return the list of numbers from
; 1 up to N)
The result is an anonymous function that takes one argument N; generates the range from 1 to N; and then for each of those numbers, generates the range from it down to 1.
Swift 5.9, 44 bytes
let f={(1...$0).map{(1...$0).reversed()+[]}}
J-uby, 19 13 bytes
:+|:*&(:+|:~)
Explanation
:+ | :* & (:+ | :~)
:+ | # Range 1..input, then
:* & ( ) # Map with...
:+ | :~ # Range 1..n, then reverse
Uiua SBCS, 7 bytes
¯⍚⇌⍚⇡⇡¯
¯⍚⇌⍚⇡⇡¯
¯ # negate
⇡ # range
⍚⇡ # range w/ boxing
⍚⇌ # reverse each
¯ # negate
Pip -p, 7 bytes
R*\,\,a
Explanation
R*\,\,a
a ; Command-line argument
\, ; Inclusive range from 1 to that number
\, ; Inclusive range from 1 to each of those numbers
R* ; Reverse each
Thunno 2, 3 bytes
RRṃ
Explanation
RRṃ # Implicit input -> 5
R # Push [1..input] -> [1 2 3 4 5]
R # Push [1..each] -> [[1] [1 2] [1 2 3] [1 2 3 4] [1 2 3 4 5]]
ṃ # Reverse each -> [[1] [2 1] [3 2 1] [4 3 2 1] [5 4 3 2 1]]
# Implicit output
Julia 1.0, 27 21 bytes
~n=1:n.|>i->[i:-1:1;]
-6 bytes (!!) thanks to MarcMush: Replace map with a broadcast .|>
Pip, -p 12 bytes
Fl\,aO R\,lx
How?
Fl\,aO R\,lx : One arg; int
a : First input(max for range)
Fl : For each in:
\,a : Range from 1 to a
\,l : Range from 1 to l(int from range)
R : Reverse
O : Output
x : Trigger output
Swift 5.6+, 42 bytes
{(1...$0).map{n->[_]in(1...n).reversed()}}
Type information (here ->[_]) is required. Without it, the return type is [ReversedCollection<ClosedRange<_>>], as the range primitive's .reversed() method is lazy by default.
SwiftFiddle link with both ways (with and without type info) to highlight the difference.
This technically isn't even full type info, as the actual type of number used is left unspecified, as _. It doesn't even necessarily have to be a builtin type as long as it meets certain requirements. With full generics, the function might look something like this (ungolfed):
func f<T: Strideable & ExpressibleByIntegerLiteral>(_ n: T) -> [[T]]
where T.Stride: SignedInteger {
return (1 ... n).map { i in
(1 ... i).reversed()
}
}
FunStack alpha, 25 bytes
Reverse map IFrom1 IFrom1
Try it at Replit!
Explanation
IFrom1 Inclusive range from 1 to the argument
IFrom1 Inclusive range from 1 to each of those numbers
Reverse map Reverse each sublist
Erlang 58 bytes
f(N)->[lists:reverse(lists:seq(1,X))||X<-lists:seq(1,N)].
Vyxal, 3 bytes
ɾɾR
Can't believe I never answered this challenge despite the fact it was asked by one of the greatest golfers I ever knew
Explained
ɾɾR
ɾ # the range [1, input]
ɾ # and that for each item in the range
R # vectorised reverse
JavaScript, 60 bytes
Without recursion:
n=>eval('for(a=[];n;a[--n]=b)for(b=[j=n];j-->1;b[n-j]=j);a')
Try it:
f=n=>eval('for(a=[];n;a[--n]=b)for(b=[j=n];j-->1;b[n-j]=j);a')
console.log(JSON.stringify(f(1)));
console.log(JSON.stringify(f(2)));
console.log(JSON.stringify(f(3)));
console.log(JSON.stringify(f(4)));
shell with seq loop, 46 bytes
for n in `seq $1`;do seq -s\ -t'\n' $n 1;done
Go, 105 bytes
func(n int)(o[][]int){for i:=1;i<=n;i++{J:=[]int{}
for j:=i;j>0;j--{J=append(J,j)}
o=append(o,J)}
return}
Pyt, 5 bytes
řĐř-⁺
Code worked on input of 3:
| Code | Stack | Description |
|---|---|---|
ř |
[1,2,3] | implicit input; řangify [1,2,...,n] |
Đ |
[1,2,3] [1,2,3] | Đuplicate |
ř |
[1,2,3] [[1],[1,2],[1,2,3]] | řangify |
- |
[[0],[1,0],[2,1,0]] | subtract |
⁺ |
[[1],[2,1],[3,2,1]] | increment; implicit print |
BQN, 10 bytes
Anonymous tacit prefix function.
(⌽1+↕)¨1+↕
Explanation
(⌽1+↕)¨1+↕
1+↕ 1. Get list of integers from 1 to n.
¨ 2a. For each integer i in the list...
( 1+↕) 2b. get a list of integers from 1 to i...
(⌽ ) 2c. and then reverse that list.
T-SQL, 145 bytes
WITH a(n)as(SELECT number FROM spt_values
WHERE'p'=type)SELECT string_agg(@+1-a.n,' ')FROM
a,a b WHERE a.n<=@ and b.n<a.n
GROUP BY b.n ORDER BY 1
Fortran (GFortran), 47 bytes
read*,i
print*,("{",(j,j=k,1,-1),"}",k=1,i)
end
Could remove 8 chars by getting rid of printed brackets if anyone would believe that they are lists otherwise.
Burlesque, 9 bytes
riroq<-pa
ri # Read int
ro # Range [1,N]
q<- # Boxed reverse
pa # Operate over ((1), (1 2), (1 2 3),...)
Alternative 9 byter, but this also has an empty list as the first element:
riroiT)<-
Zsh, 22 bytes
eval echo {{1..$1}..1}
{{1..$1}..1} -> {1..1} {2..1} {3..1} {4..1} ...
eval echo {1..1} {2..1} {3..1} ... -> echo 1 2 1 3 2 1 ...
If the sublists must be delimited, then 25 bytes for , or 26 bytes for newline.
Java (JDK), 98 bytes
n->{int a[][]=new int[n][],i=0,j;for(;i<n;)for(a[i]=new int[j=++i];j>0;)a[i-1][--j]=i-j;return a;}
Perl 6 Raku, 24 15 13 10 bytes
-2 removed parenthesis
-3 thanks to nwellnhof
^*+1 X…1
Explanation
^*+1 # make a range from 1 .. argument (whatever star).
X…1 # create ranges descending to 1 using cross product metaoperator.
Previous version, 24 bytes
(^<<(^*+1)X+1)>>.reverse
Explanation
^*+1 # make a range from 1 .. argument (whatever star)
^<<( ) # replace each element with a range from 0 .. element - 1
# (via hyper prefix operator)
X+1 # shift the range to 1 .. element
# (via cross product metaoperator)
( )>>.reverse # reverse each list (via hyper method operator)
C (gcc), 42
I felt like there must be an elegant recursive solution to this. This is the shortest I could come up with, though there is probably more room for golf.
- 4 bytes saved thanks to @S.S.Anne.
f(n,m){n&&f(n-m/n,m%n+1)*printf("%d ",m);}
Initially, the function is called as f(N, 1), where N is the input integer.
Haskell, 27 bytes
f n=scanl(flip(:))[1][2..n]
Haskell, 74 73 51 bytes
main=do i<-getLine;print[[x,x-1..1]|x<-[1..read i]]
-22 bytes thanks to @79037662
x86-16 machine code, 12 bytes
Binary:
00000000: 33c0 4050 ab48 75fc 58e2 f7c3 3.@P.Hu.X...
Unassembled listing:
33 C0 XOR AX, AX ; AX = 0
OUT_LOOP:
40 INC AX ; start at 1
50 PUSH AX ; save starting position
IN_LOOP:
AB STOSW ; write to output buffer, increment DI
48 DEC AX ; AX--
75 FC JNZ IN_LOOP ; if AX > 0, keep looping
58 POP AX ; restore starting position
E2 F7 LOOP OUT_LOOP
C3 RET ; return to caller
Input Number in CX, output array of WORD, at [DI].
Example I/O using DOS test driver program:
MathGolf, 4 bytes
╒╒mx
Explanation:
╒ # Push a list in the range [1, (implicit) input-integer]
╒ # Convert each inner value to a list in the range [1, value]
m # Map over this list of lists:
x # And reverse each inner list
# (after which the entire stack joined together is output implicitly as result)
Brachylog, 5 bytes
⟦₁⟧₁ᵐ
Explanation
⟦₁ Ascending range from 1 to the input
ᵐ Map:
⟧₁ Descending range from 1 to the mapped element
J, 11 bytes
[:<@|.\1+i.
i. a list 0..n-1
+ add
1 one to it -> a list 1..n
\ for each prefix of the list (1, 1 2, 1 2 3...)
|. reverse
@ and
< box
[: cap the fork
K (oK), 14 bytes
{{|1+!x}'1+!x}
{ } a function with parameter x
!x a list 0..n-1
1+ add one to it -> a list 1..n
{ }' apply this function to each of the elements of the above list
!x a list 0..n-1
1+ add one to it -> a list 1..n
| reverse
Jelly, 3 bytes
RRU
R Range from 1 to input
R (implicitly) map over said range and create a range from 1 to this element
U reverse each of those
You can try it online!
Courtesy of @JonathanAllan, we also have two other 3-"byters"
RrL
RrE
I think it is not often that golfing languages solve a challenge with only a-zA-Z characters
Retina, 20 bytes
.+
*
L$w`_+
$.&
O$^`
Try it online! Explanation:
.+
*
Convert the input to a string of _s of that length.
L$w`_+
$.&
List the lengths of all the possible substrings. The way Retina enumerates substrings means that the lengths are in the exact reverse of the desired order.
O$^`
Reverse the output line-by-line.
PHP, 54 bytes
function($x){for(;$y<$x;$a[]=range(++$y,1));return$a;}
Or recursive:
PHP, 54 bytes
function f($x){return$x?f($x-1)+[$x=>range($x,1)]:[];}
Or with PHP-formatted printed output:
PHP, 38 bytes
for(;$x<$argn;print_r(range(++$x,1)));
JavaScript (ES6), 50 49 bytes
Saved 1 byte thanks to @Shaggy
f=n=>n?[...f(n-1),(g=_=>n?[n,...g(--n)]:[])()]:[]
R, 22 19 bytes
Map(`:`,1:scan(),1)
Map(f,...) applies f elementwise to each member of ..., recycling as needed, resulting in a list, so we just supply 1 as the to argument to : to get the reversed.
-3 bytes thanks to Vlo!
Charcoal, 9 bytes
IEN⮌E⊕ι⊕μ
Try it online! Link is to verbose version of code. Explanation:
N Input as a number
E Map over implicit 0-indexed range
ι Current index
⊕ Incremented
E Map over implicit 0-indexed range
μ Inner index
⊕ Incremented
⮌ Reversed
I Cast to string for implicit print
There are other ways of getting the inner range such as InclusiveRange(1, Incremented(i)) and Range(1, Plus(2, i)) for the same byte count.
shell + sed, 15 bytes
seq $1|sed G\;h
Outputs like so, 1\n\n2\n1\n\n3\n2\n1\n\n[...]
seq $1 creates a sequence from 1 to the first argument $1
|sed ... which is piped into a sed script
sed works on a line-by-line basis; it first reads the first line into the buffer, called the "pattern space", after which the program commands is run on it. At the end of the program's execution on the first line, the remaining pattern space is implicitly printed. Then sed reads the next line into the pattern space, replacing the previous contents, and runs the commands on it, repeating for all lines of input (unless a command specifies otherwise).
The pattern space is not saved between lines, but what is is the hold space. The hold space is another buffer, that starts empty, and can be modified by program commands. Its contents are carried on to the execution of the next line of input.
The G command appends a newline followed by the content of the hold space to that of the pattern space. Then the h command replaces the hold space with the content of the pattern space. This effectively reverses the lines of input encountered so far, writing them to the pattern space – implicitly printing at the end of processing the current line – and saving them to the hold space so that upon reading subsequent lines of input, the new reversed "list" can be constructed with G;h.
The ; is escaped in the program as \; because otherwise the shell interprets it as terminating a shell command.
APL (Dyalog Unicode), 5 4 bytesSBCS
Anonymous tacit prefix function.
,⍨\⍳
,⍨\ cumulative reverse-concatenation reduction of
⍳ the iota
GolfScript, 12 (13) bytes
,{)),(;-1%}%`
,{)),(;-1%}%` #Reversed iota of iota
, #0 to n-1 iota
{ }% #For each element in the iota
{)) } #Increment by 2
{ , } #Iota
{ (; } #Pop leading 0
{ -1%} #Reverse it
` #Pretty output, not needed if you use a better stack-interpreter
Below is my old solution, I gained inspiration after posting and improved it.
),(;{),(;-1%}%`
Comma is the function that builds an array 0 to n-1, "iota expand".
),(;{),(;-1%}%` #Take in a number, output reversed expanded iota
) #Increment input by 1
, #Iota expand
(; #Remove leading 0
{ }% #For every element, do the following
{) } #Increment by 1
{ , } #Iota expand
{ (; } #Remove leading 0
{ -1%} #Reverse
` #Pretty output; technically not needed
PowerShell, 19 bytes
1.."$args"|%{$_..1}
Generates the range from 1 to input $args, then constructs the reversed range for each of those numbers. Tack on a -join to better see how the arrays are created (because PowerShell inserts a newline between each element, it's tough to see the individual arrays).
