[Question]
  [
Let's start with the natural numbers
```
[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,100...
```
Now we will make a new list, replacing each natural number `n` with a countdown from `n` to `1`.
```
[1,2,1,3,2,1,4,3,2,1,5,4,3,2,1,6,5,4,3,2,1,7,6,5,4,3,2,1,8,7,6,5,4,3,2,1,9,8,7,6,5,4,3,2,1,10,9,8,7,6,5,4,3,2,1,11,10,9,8,7,6,5,4,3,2,1,12,11,10,9,8,7,6,5,4,3,2,1,13,12,11,10,9,8,7,6,5,4,3,2,1,14,13,12,11,10,9,8,7,6..
```
Now we will repeat the process.
```
[1,2,1,1,3,2,1,2,1,1,4,3,2,1,3,2,1,2,1,1,5,4,3,2,1,4,3,2,1,3,2,1,2,1,1,6,5,4,3,2,1,5,4,3,2,1,4,3,2,1,3,2,1,2,1,1,7,6,5,4,3,2,1,6,5,4,3,2,1,5,4,3,2,1,4,3,2,1,3,2,1,2,1,1,8,7,6,5,4,3,2,1,7,6,5,4,3,2,1,6..
```
And now we will do it a third time:
```
[1,2,1,1,1,3,2,1,2,1,1,2,1,1,1,4,3,2,1,3,2,1,2,1,1,3,2,1,2,1,1,2,1,1,1,5,4,3,2,1,4,3,2,1,3,2,1,2,1,1,4,3,2,1,3,2,1,2,1,1,3,2,1,2,1,1,2,1,1,1,6,5,4,3,2,1,5,4,3,2,1,4,3,2,1,3,2,1,2,1,1,5,4,3,2,1,4,3,2,1...
```
This is the **triple countdown sequence**.
Your task is to implement the triple countdown sequence. You may either take input and give the value of the sequence at that index, or you may simply output the terms starting from the beginning without stop.1
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so answers will be scored in bytes with fewer bytes being the goal.
---
1: Both zero and one indexing are permitted. Outputting the terms without halt includes lazy structures which can produce an infinite number of terms.
  
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 12 bytes
Returns the *n*th number in the series.
```
⊢⊃1(∊…¨⍨)⍣3⍳
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn//1HXokddzYYajzq6HjUsO7TiUe8KzUe9i40f9W7@n/aobcKj3j6g/KPeNY96txxab/yobeKjvqnBQc5AMsTDM/h/moIhV5qCERAbA7EJEJsCsRkQmwOxBRBbArGhAQA "APL (Dyalog Extended) – Try It Online")
`⊢` the argument
`⊃` picks the element from
`1(`…`)⍣3⍳` repeat thrice with 1 as constant left argument and **i**ndices 1 through *n* as initial right argument:
 `∊` **e**nlist (flatten)
 `…` the sequence
  `¨` for each
   `⍨` with swapped arguments, i.e. counting down from that number to 1
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
```
∞3FLí˜
```
[Try it online!](https://tio.run/##yy9OTMpM/f//Ucc8Yzefw2tPz/n/HwA "05AB1E – Try It Online")
Infinitely outputs, thanks to Kevin Crujisen
# [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
```
L3FLí˜
```
[Try it online!](https://tio.run/##yy9OTMpM/f/fx9jN5/Da03P@/zc0AAA "05AB1E – Try It Online")
I doubt it could be beaten
[Answer]
# [Haskell](https://www.haskell.org/), ~~34~~ ~~33~~ 32 bytes
-1 byte thanks to [Wheat Wizard](https://codegolf.stackexchange.com/users/56656/wheat-wizard)!  
-1 byte thanks to [pxeger](https://codegolf.stackexchange.com/users/97857/pxeger)!
```
[1..]>>=f>>=f>>=f
f x=[x,x-1..1]
```
[Try it online!](https://tio.run/##y0gszk7NyfmfbhvzP9pQTy/Wzs42DYa50hQqbKMrdCp0gTKGsf9zEzPzbAuKMvNKFNL//0tOy0lML/6vm1xQAAA "Haskell – Try It Online")
[Answer]
# [jq](https://stedolan.github.io/jq/), 50 bytes
```
def f:[range(.)+1]|reverse[];
1|while(1;.+1)|f|f|f
```
[Try it online!](https://tio.run/##yyr8/z8lNU0hzSq6KDEvPVVDT1PbMLamKLUstag4NTrWmsuwpjwjMydVw9BaT9tQsyYNBP///5dfUJKZn1f8XzcPAA "jq – Try It Online")
funny how similar the second line is to the Zsh answer.
-1 from ovs.
[Answer]
# [Zsh](https://www.zsh.org/), 37 bytes
```
c()xargs -i seq {} -1 1
seq inf|c|c|c
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjwcLqpaUlaboWN1WTNTQrEovSixV0MxWKUwsVqmsVdA0VDLlA7My8tJpkEIQoXlVbk5GamKKgq2IIEVgabWhgELsAwgEA)
Full program which outputs infinitely, one per line (ATO link includes a wrapper to halt after N terms).
"Implicit" "list" "flattening" FTW! (Zsh doesn't actually have any of these features - it's just text!)
`c` is a function that outputs the `seq`uence from `{}` to `1` (with a step of `-1`) for each `{}` in the input (`xargs -i`). Then output "all" integers and pipe that to `c` three times.
[Answer]
# [JavaScript (V8)](https://v8.dev/), 60 bytes
```
for(a=1;;a++)for(i=a;--i;)for(j=i;--j;)for(k=j;--k;)print(k)
```
[Try it online!](https://tio.run/##JcfBCoAwCADQ35kMD90C8WMkCFRow8Z@31a92zOZch@hfeDcM88WRXgjklrhjbIQotIXY12xP8624gQ99BrFIfMB "JavaScript (V8) – Try It Online")
Boring trivial solution.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 6 bytes
```
!4¡ṁṫN
```
[Try it online!](https://tio.run/##yygtzv7/X9Hk0MKHOxsf7lzt9/8/AA "Husk – Try It Online")
outputs an infinite list.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 36 bytes
```
Do[Print[0;],{,∞},#,#,#]&@{,,1,-1}
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78/98lPzqgKDOvJNrAOlanWudRx7xaHWUQjFVzqNbRMdTRNaz9/x8A "Wolfram Language (Mathematica) – Try It Online")
Prints elements indefinitely.
---
A somewhat more interesting solution which generalizes to \$n\$-countdown sequences:
### [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 48 bytes
```
Nest[gArray[g,#,{#,1}]&,Print,3]@i~Do~{i,∞}
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78/98vtbgkOv39pIWORUWJldHpOso61co6hrWxajoBRZl5JTrGsQ6ZdS75ddWZOo865tX@/w8A "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [PowerShell Core](https://github.com/PowerShell/PowerShell), 33 bytes
Outputs terms without stopping!
```
filter s{$_..1}
for(){++$x|s|s|s}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNydFNzi9K/f8/LTOnJLVIobhaJV5Pz7CWKy2/SMNapUI3J9VUs1pbW6WiphgEa/9z/QcA "PowerShell Core – Try It Online") *Note: the linked TIO limits the output*
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
r1)⁺⁺Fị@
```
[Try it online!](https://tio.run/##y0rNyan8/7/IUPNR4y4gcnu4u9vh/@H2R01r/v83MgAA "Jelly – Try It Online")
Because it is extremely cumbersome to produce infinite output in Jelly, it instead applies countdown 3 times to the input's range and outputs the input-th item. The part without indexing (6 bytes) ties with [05AB1E's equivalent](https://codegolf.stackexchange.com/a/235530/78410).
```
r1)⁺⁺Fị@    Monadic main link. Input = n
r1)         [x,x-1..1] for each number x (autorange)
   ⁺⁺       Do the above; do the above (no autorange)
     Fị@    Flatten and get the nth item
```
[Answer]
# Scala, 60 bytes
```
Stream.from(1)flatMap>flatMap>flatMap>
def> =(_:Int)to(1,-1)
```
[Try it in Scastie!](https://scastie.scala-lang.org/jfpbO2ekQre7BbIOSmxdGg)
~~A less trivial solution should be coming soon.~~
`>` is a function that takes an `Int` and returns a range going from that number to 1. We then take an infinite `Stream` starting at 1, and apply `>` to each of those numbers thrice, flattening each time.
[Answer]
# [Raku](http://raku.org/), 33 bytes
```
(1..*,{.flatmap:{$_...1}}...*)[3]
```
[Try it online!](https://tio.run/##K0gtyjH7n1up4JCoYPtfw1BPT0unWi8tJ7EkN7HAqlolXk9Pz7C2FkhqaUYbx/63VihOBCmOjjM0MIj9DwA "Perl 6 – Try It Online")
This is a lazy list of countdown sequences, where the first element is the list of natural numbers, the second is the countdown sequence, the third is the double countdown sequence, and the fourth is the triple countdown sequence, et cetera. The triple countdown sequence is the one at index `3`, which is returned.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 45 bytes
```
Flatten[r@r@r@Range@#][[#]]&
r=Range[#,1,-1]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773y0nsaQkNS@6yAEEgxLz0lMdlGOjo5VjY9W4imzBAtHKOoY6uoaxav8DijLzShT0HdL1oUrNDP7/BwA "Wolfram Language (Mathematica) – Try It Online")
-23 bytes from @att
[Answer]
# [R](https://www.r-project.org/), ~~59~~ 51 bytes
```
`[`=`for`;while(F<-F+1)i[F:1,j[i:1,k[j:1,show(k)]]]
```
[Try it online!](https://tio.run/##K/r/PyE6wTYhLb8owbo8IzMnVcPNRtdN21AzM9rNylAnKzoTSGZHZwHJ4oz8co1szdjY2P//AQ "R – Try It Online")
Prints the resulting sequence infinitely.
---
Less boring:
### [R](https://www.r-project.org/), 68 bytes
```
`!`=unlist;s=sapply;while(F<-F+1)cat(!s(!s(F:1,seq,,-1),seq,,-1),"")
```
[Try it online!](https://tio.run/##K/r/P0ExwbY0LyezuMS62LY4saAgp9K6PCMzJ1XDzUbXTdtQMzmxREOxGITcrAx1ilMLdXR0DTURDCUlzf//AQ "R – Try It Online")
[Answer]
# [C++ (gcc)](https://gcc.gnu.org/), 101 bytes
```
#include<cstdio>
int a,x,y,z;main(){for(;;)for(x=a++;x--;)for(y=x;y--;)for(z=y;z;)printf("%d,",z--);}
```
[Try it online!](https://tio.run/##Sy4o0E1PTv7/XzkzLzmnNCXVJrm4JCUz344rM69EIVGnQqdSp8o6NzEzT0OzOi2/SMPaWhNEVdgmamtbV@jqQriVthXWlTBOlW2ldZW1ZkER0Ig0DSXVFB0lnSpdXU3r2v//AQ "C++ (gcc) – Try It Online")
[Answer]
# [Factor](https://factorcode.org/) + `combinators.extras lists lists.lazy`, 58 bytes
```
[ 1 lfrom [ [ 1 [a,b] >list ] lmap-lazy lconcat ] thrice ]
```
Running in the listener, as `lmap-lazy` postdates build 1525, the one TIO uses. Note that output has been limited to 30 so I could actually take the screenshot. This limitation is not present in the code itself.
[![enter image description here](https://i.stack.imgur.com/1Bay9.png)](https://i.stack.imgur.com/1Bay9.png)
## Explanation
It's a quotation (anonymous function) that returns an infinite lazy list of the triple countdown sequence.
* `1 lfrom` An infinite lazy list of the natural numbers.
* `[ ... ] thrice` Apply a quotation (to the natural numbers) three times.
* `[ ... ] lmap-lazy` Use a quotation to map over a lazy list.
* `1 [a,b] >list` Create a list from an input number to one. e.g. `5` -> `L{ 5 4 3 2 1 }`
* `lconcat` Concatenate a list of lists into a single list.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 69 bytes
Nested Ternary operator solution.
`a`, `b` and `c` are the triple countdown state from fastest to slowest, and `d` is the increasing count. `a` is printed for every step in the countdown. (make that a+1 thanks to AZTECCO
Thanks to AZTECCO for -10 bytes!! And -2 more!!!
It took me an embarrassingly long time to figure out what's going on with the last suggestion, that's some serious golfing.
```
a,b,c,d;main(){for(;;a=!a?b=!b?c-=c?1:--d:b-1:a-1)printf("%d,",a+1);}
```
[Try it online!](https://tio.run/##BcHBCoAgDADQb1EIlLbDrg7xW@bE8JCFdIu@fb2neKiaCVRQaHzKmCG@/VqBWbKTUrOrRTFroYTYUkVKghTvNebTg98aeJCdIn9mPw "C (gcc) – Try It Online")
[Answer]
# [Swift](https://swift.org/), 103 bytes
```
let a:([Int])->[Int]={$0.flatMap{(1...$0).reversed()}};(1...).forEach{a(a(a([$0]))).forEach{print($0)}}
```
Functional programming in Swift, excepting the `print` call, which obviously is non-pure.
`a` is a closure that converts an array of integers to an array of their countdown, which is called three times for every number.
[Try it online!](https://tio.run/##Ky7PTCsx@f8/J7VEIdFKI9ozryRWU9cOTNtWqxjopeUklvgmFlRrGOrp6akYaOoVpZalFhWnpmho1tZag0U19dLyi1wTkzOqEzVAMFrFIFZTEyFaUJSZV6IB1Ftb@/8/AA "Swift – Try It Online")
[Answer]
# [Nibbles](http://golfscript.com/nibbles), 6 bytes
```
<$/, 3,~.@\, 
```
explanation
```
<$      # first int input elements
  /     # fold
   ,3   # [1,2,3] (any list of length 3 would work)
   ,~   # [1,2,...inf] (initial value to fold)
   .@   # map on accumulator
     \, # reverse of list from 1 to
        # implicit $ (the element of list to map)
```
[Answer]
# [Python 3](https://docs.python.org/3/), 72 bytes
```
def c(x,i):i>0<x!=(print(x),c(x-1,i),c(x-1,i-1))
i=1
while 1:c(i,2);i+=1
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFZo0InU9Mq087ApkLRVqOgKDOvRKNCUwcormsIlIExdA01NbkybQ25yjMyc1IVDK2SNTJ1jDStM7VtDf//BwA "Python 3 – Try It Online")
-19 bytes thanks to Wheat Wizard by using even more recursion  
-1 byte thanks to ovs
[Answer]
# [JavaScript (V8)](https://v8.dev/), 51 bytes
```
e=f=>i=>{for(;--i;)f(i)};e(_=>e(e(e(print)))(-_))``
```
[Try it online!](https://tio.run/##FcIxCoAwDAXQ6@QP2YWSXqUtkkActNTSRTx7RN472mr3PrxPXluEikl2yY9dgxKzJxg53qRUJCv9@vBzAiAuQK0RHw "JavaScript (V8) – Try It Online")
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 9 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
)╒3æ╒mx─§
```
Outputs the 0-based value.
[Try it online.](https://tio.run/##y00syUjPz0n7/1/z0dRJxoeXAcncikdTGg4t///fgMuQy4jLmMuEyxDINOUyNwAA)
**Explanation:**
```
)          # Increase the (implicit) input-integer by 1 (work-around for input 0)
 ╒         # Pop and push a list in the range [1,input+1]
  3æ       # Loop 3 times, using four characters as inner code-block:
    ╒      #  Convert each integer in the list to a [1,n] ranged list
     m     #  Map over each list:
      x    #   Reverse the list
       ─   #  Flatten the list of lists
        §  # After the loop, get the value at the (implicit) input as index
           # (after which the entire stack is output implicitly as result)
```
[Answer]
# [C++ (gcc)](https://gcc.gnu.org/), ~~132~~ ~~123~~ ~~114~~ ~~113~~ 112 bytes
```
#include<argp.h>
main(int a,int b){if(a<2)for(;;)main(2,a++);while(--b)if(a<4)main(a+1,b);else printf("%d,",b);}
```
[Try it online!](https://tio.run/##Sy4o0E1PTv7/XzkzLzmnNCXVJrEovUAvw44rNzEzTyMzr0QhUQdEJmlWZ6ZpJNoYaablF2lYW2uC5Y10ErW1Na3LMzJzUjV0dZM0wWpMIJKJ2oY6SZrWqTnFqQoFRUBD0jSUVFN0lECCtf//AwA "C++ (gcc) – Try It Online")
Thanks to @wheat-wizard for tip on removing all whitespace
[Answer]
# [Julia 1.0](http://julialang.org/), 56 bytes
```
~i=i:-1:1
!i=[.~i...;]
for i=1:-1%UInt println.(!!!i)end
```
[Try it online!](https://tio.run/##yyrNyUw0rPj/vy7TNtNK19DKkEsx0zZary5TT0/POpYrLb9IIdPWECijGuqZV6JQUJSZV5KTp6ehqKiYqZmal/L/PwA "Julia 1.0 – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 13 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
There's gotta be a better way than this.
Outputs the `n`th term, 0-indexed.
```
gÈc!õ1}g3NËôÄ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=Z8hjIfUxfWczTsv0xA&input=MjU)
[Answer]
# [Perl 5](https://www.perl.org/), 48 bytes
```
sub d{sub c{map{reverse 1..$_}@_}sub{c c c++$i}}
```
[Try it online!](https://tio.run/##K0gtyjH9/7@4NEkhpRpEJlfnJhZUF6WWpRYVpyoY6umpxNc6xNcCpaqTFYBQW1sls7b2f0FRZl6JBlCpQrWSSryOUq1Ciq6dhqamQnlGZg5Q338A "Perl 5 – Try It Online")
Returns an anonymous sub that can be called repeatedly to obtain the next list of items in the sequence. Ungolfed and commented:
```
sub d {
    sub c {
        # This is where the magic happens. c(1) returns (1), c(2) returns (2, 1).
        # c(1, 2, 3) returns (1, 2, 1, 3, 2, 1)
        return map {reverse 1 .. $_} @_;
    }
    # 3 nested calls to c() to get the triple countdown
    return sub{c(c(c(++$i)))};
}
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 48 bytes
```
x=0
loop{x-=1;eval"(x...0).map{|x|"*3+"p -x}}}"}
```
[Try it online!](https://tio.run/##KypNqvz/v8LWgCsnP7@gukLX1tA6tSwxR0mjQk9Pz0BTLzexoLqmokZJy1hbqUBBt6K2tlap9v9/AA "Ruby – Try It Online")
* outputs infinitely
We eval "(x...0).map{|x|"\*3 which becomes a depth 3 loop
x is decremented thus negative so that we can use range x..0
Then we put -x
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 9 bytes
```
ɾṘ3(vɾf)Ṙ
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=%C9%BE%E1%B9%983%28v%C9%BEf%29%E1%B9%98&inputs=5&header=&footer=)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 36 bytes
```
Ｎθ≔⁰ηＷ›θＬυ«≦⊖ηＦ…η⁰Ｆ…κ⁰Ｆ…λ⁰⊞υμ»Ｉ±§υ⊖θ
```
[Try it online!](https://tio.run/##ZY7NCsIwEITP7VPkuIEI9eKlp6IghVqKbxDbNSmmac2PCuKzx5R6KLi3GeabnVZy045chVDqybvaDxc0cKd5WljbCw0ZIzKqp@wVEjga5G4OMFKhFk6Cp5SSd5qc@PQjDtgaHFA77BY2uY6GwJlrgSAZySKwcm5/jlqcxttYz8gQKz5pY3rtYM@tgxpFHAGFK3WHrzmyehm3z5eHsN2FzUN9AQ "Charcoal – Try It Online") Link is to verbose version of code. Outputs the 1-indexed `n`th value. Explanation: Based on @AZTECCO's answer, generates the triple countup sequence for the negated natural numbers, and then negates the final value to produce the desired result.
```
Ｎθ
```
Input `n`.
```
≔⁰η
```
Start with no terms.
```
Ｗ›θＬυ«
```
Repeat until we have at least `n` terms.
```
≦⊖η
```
Get the next negated natural number.
```
Ｆ…η⁰Ｆ…κ⁰Ｆ…λ⁰⊞υμ
```
Generate the triple countup for that number.
```
»Ｉ±§υ⊖θ
```
Output the `n`th term, negating to give the desired result.
[Answer]
# [Burlesque](https://github.com/FMNSSun/Burlesque), 14 bytes
```
r1{m{ro^p}}3E!
```
[Try it online!](https://tio.run/##SyotykktLixN/f@/yLA6t7ooP66gttbYVfH/fwA "Burlesque – Try It Online")
```
r1    # Range 1..inf
{
 m{   # Apply to each
  ro  # Range from 1..N
  ^p  # Push in reverse
 }
}
3E!   # Run 3 times
```
]