47
\$\begingroup\$

The Challenge

Output a list of years that starts with the current year and ends 120 years ago. The birth year of every living human would be included in this list.

Details

The list should be in descending order.

Every built-in function to manipulate arrays and/or lists is allowed.

Shortest code in bytes wins.

When run this year 2016, the output would be

2016, 2015, ..., 1897, 1896

When run next year 2017, the output would be

2017, 2016, ..., 1898, 1897

Etc.

Update

  • Some have asked about the format of the list. As most have guessed, it doesn't matter. Insert any separator between the numbers. Intuitively most inserted a comma or space or both, newline or output an array.
  • Quasi superhumans like Jeanne Calment are an exception to the rule stated in my question.
\$\endgroup\$
12
  • 8
    \$\begingroup\$ I recommend the sandbox for getting feedback before posting a challenge (not just for your first challenge - most of us use it for every challenge). \$\endgroup\$ Commented Aug 11, 2016 at 11:31
  • 4
    \$\begingroup\$ I don't see anything wrong with this challenge. One thing that might be worth specifying is whether the output should always start with 2016, or with the year in which it is run (will it start with 2017 if run next year?). This will affect whether it is a fixed output challenge, or needs to access the current date. \$\endgroup\$ Commented Aug 11, 2016 at 11:33
  • 21
    \$\begingroup\$ Jeanne Louise Calment lived 122 years. \$\endgroup\$
    – Zenadix
    Commented Aug 11, 2016 at 15:32
  • 12
    \$\begingroup\$ Lad, that was way too early of an accept. \$\endgroup\$ Commented Aug 11, 2016 at 17:30
  • 8
    \$\begingroup\$ Is the challenge: "Print all the numbers from y - 120 to y" or "print all the birth years of living people"? Because if someone born in 1896 is alive today, that doesn't mean that there are also still people from 1898 around. \$\endgroup\$
    – CompuChip
    Commented Aug 14, 2016 at 9:58

69 Answers 69

19
\$\begingroup\$

Pyke, 6 bytes

wC7m-

Try it here!

w     - 121
   m- - for i in range(^):
 C7   -  current_year-i

(After w, the codepoint for 153 is present but it isn't printable)

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Wow, that was a quick checkmark. Maybe wait for a Jelly answer? \$\endgroup\$
    – Adám
    Commented Aug 11, 2016 at 15:10
  • \$\begingroup\$ Whilst I agree it was a quick checkmark, I doubt even Jelly can do it in 5 \$\endgroup\$
    – Blue
    Commented Aug 11, 2016 at 15:28
  • \$\begingroup\$ Why do you have a variable for 121? Just because it is a square number? But well done! \$\endgroup\$
    – Denker
    Commented Aug 11, 2016 at 16:00
  • 3
    \$\begingroup\$ The w actually has an unprintable byte afterwards that makes it 121 \$\endgroup\$
    – Blue
    Commented Aug 11, 2016 at 16:02
  • 1
    \$\begingroup\$ @LeakyNun it's configurable, whatever the default for the server it's running on. On pyke.catbus, I set it to Windows-1252 \$\endgroup\$
    – Blue
    Commented Aug 11, 2016 at 16:10
11
\$\begingroup\$

Pyth, 11 9 8 bytes

-L.d3C\y

Works by mapping over the range [0...120] and subtracting every number from the current year. The range is built implicitly by using 121 as the map argument. To avoid a separating whitespace between .d3 and 121 we get this number by converting y to it's codepoint.
Thanks to @FryAmTheEggman for coming up with this approach!

Try it here!

Old 9-byte solution:

_>121S.d3

Try it here!

Builds the range [1...<current year>] and only takes the last 121 elements of it.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ You should reverse the list so that it starts with the current year \$\endgroup\$ Commented Aug 11, 2016 at 12:27
  • 1
    \$\begingroup\$ -L... saves a few bytes. \$\endgroup\$
    – Jakube
    Commented Aug 11, 2016 at 12:28
  • 1
    \$\begingroup\$ @ChristiaanWesterbeek Missed that part, fixed. Thanks for spotting! \$\endgroup\$
    – Denker
    Commented Aug 11, 2016 at 12:33
  • \$\begingroup\$ @Jakube Used a different approach now, but thanks for the reminder that this exists, didn't use Pyth a lot in the last time! \$\endgroup\$
    – Denker
    Commented Aug 11, 2016 at 12:34
  • 1
    \$\begingroup\$ -L.d3C\y should work for 8. \$\endgroup\$ Commented Aug 11, 2016 at 12:38
9
\$\begingroup\$

R, 34 bytes

(format(Sys.Date(),"%Y"):0)[1:121]

See here on an online interpreter.

Edit Could be reduced to 33 bytes by using substr.

(substr(Sys.Date(),1,4):0)[1:121]

but technically this solution will only work until the 9999-12-31.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ This is awesome. I did not know it could typecast a string into a number when using the : operator... \$\endgroup\$ Commented Aug 11, 2016 at 22:27
8
\$\begingroup\$

AngularJS + Lodash, 274 bytes

angular.module('x',[]).controller('x',['$scope',function(x){x.x=_.range(9,new Date().getFullYear()+1).slice(-121).reverse()}])
<script src=//goo.gl/M5LvGe></script><script src=//goo.gl/opljJl></script><select ng-app=x ng-controller=x multiple><option ng-repeat="x in x">{{x}}

Output

enter image description here

\$\endgroup\$
8
\$\begingroup\$

BASH + coreutils, 35 33 bytes

x=`date +%Y`;seq $x -1 $((x-120))
\$\endgroup\$
3
  • 2
    \$\begingroup\$ in your case, quotes are unneeded: change : date +"%Y" into date +%Y \$\endgroup\$ Commented Aug 11, 2016 at 16:26
  • 1
    \$\begingroup\$ x=`date +%Y`;seq $x -1 $[x-120] or seq $[x=`date +%Y`] -1 $[x-120] works as well. \$\endgroup\$
    – Dennis
    Commented Aug 11, 2016 at 17:48
  • \$\begingroup\$ 10 bytes shorter if you have OSX or are willing to install jot on Linux \$\endgroup\$ Commented Aug 12, 2016 at 0:11
7
\$\begingroup\$

CJam, 14 12 11 bytes

Saved 2 bytes thanks to Sp3000 and 1 byte thanks to Martin Ender

et0=121,f-p

Try it online!

Explanation

et0=         e# Push the current year
    121,     e# Push the range 0, 1, ..., 120
        f-   e# For each item in the range, subtract it from current year
          p  e# Print the array
\$\endgroup\$
0
7
\$\begingroup\$

HP50g RPL, 97 bytes

120 'S' STO DATE ->STR 6 9 SUB OBJ-> 'Y' STO {} S WHILE 0 >= REPEAT Y S - + 'S' DECR END REVLIST

Ungolfed:

120
'span' STO     @ Store the span of years to cover.
DATE           @ Get the date as number 11.082016. 
→STR           @ Convert to string "11.082016".
               @ (Number format must allow all these decimal places.)
6 9 SUB        @ "11.082016" Substring for the year.
               @       ^  ^
               @  123456789
OBJ→           @ Convert string to number.
'year' STO     @ Store as the year to start at.
{} span        @ Start empty list to collect the years.
               @ Leave loop counter on the stack.
WHILE 0 ≥      @ Loop until the counter goes negative.
REPEAT
  year span -  @ E.g. on first iteration: 2016 - 120 = 1896.
  +            @ Append the year to the list on the stack.
  'span' DECR  @ Decrement loop counter and leave on stack.
END
REVLIST        @ Put list in reverse chronological order.

Showing a list of 2016 down to 1896:

2016 to 1896

\$\endgroup\$
1
  • \$\begingroup\$ Edited answer to get the current year from the calculator. \$\endgroup\$
    – Caleb Paul
    Commented Aug 11, 2016 at 19:41
6
\$\begingroup\$

05AB1E, 8 7 bytes

Code:

žg120Ý-

Explanation:

žg         # Get the current year.
  120Ý     # Create the list [0, 1, ..., 119, 120].
      -    # Substract, which leaves [year - 0, year - 1, ..., year - 120].

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

\$\endgroup\$
6
\$\begingroup\$

PowerShell, 26 24 bytes

@TimmyD improved version:

0..120|%{(date).Year-$_}

Was:

($d=(date).year)..($d-120)

where date runs Get-Date

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Blargh, should have answered earlier. That's exactly the straightforward version I had ready. Then work interfered :D A fun version would also be: ((date).year..0)[0..120]; alas it's not shorter. \$\endgroup\$
    – Joey
    Commented Aug 11, 2016 at 14:35
  • 1
    \$\begingroup\$ I find it interesting that date is equivalent to Get-Date when date is actually not an alias to Get-Date. I've seen this called the "implied verb" rule and it is rarely ever documented in PowerShell literature. \$\endgroup\$
    – Bevo
    Commented Aug 13, 2016 at 1:04
  • \$\begingroup\$ @Bevo It's useful for CodeGolf, but a bit risky for any other use. See: codegolf.stackexchange.com/a/778/571 and comment chain; it's both prone to name clashes and very slow. \$\endgroup\$ Commented Aug 13, 2016 at 1:11
6
\$\begingroup\$

Dyalog APL, 11 10 bytes

120↑⌽⍳⊃⎕ts

120↑ take 120 elements

of the reversed

indices until

the first element of

⎕TS TimeStamp in the format [YYYY, M, D, h, m, s, t]

TryAPL online!


Old version:

(⊃⎕TS)-⍳120

⊃⎕TS first element of [YYYY, M, D, h, m, s, t]

- minus

⍳120 [0, 1, 2, ..., 118, 119]

Requires ⎕IO←0, which is default on many systems.

TryAPL online!

\$\endgroup\$
6
\$\begingroup\$

Vitsy + *sh + JavaScript, 33 26 21 18 bytes

Vitsy doesn't have native time/date retrieval, so I had to use shell and eval for this one.

Thanks to @Caleb for helping me shear off another 3 bytes!

'Y%+ etad',Dca*-HZ

'Y%+ etad'               Push the string 'date +"%Y"' to the stack.
          ,              Execute through shell. 
           Dca*-         Dupe n, push n - 120.
                H        Pop x, y, push range(x, y) to the stack.
                 Z       Output all stack as characters.

You can't try this one online, because it uses both shell AND eval.

Output is as character codes.

\$\endgroup\$
2
  • \$\begingroup\$ You should be able to trim a couple bytes off of this because you don't need the double quotes around the date format string (since there are no spaces in it); date +%Y works just fine. \$\endgroup\$
    – Caleb
    Commented Aug 11, 2016 at 16:13
  • \$\begingroup\$ @Caleb Perfect, thanks! Made the need for a JS eval non-existent as well. \$\endgroup\$ Commented Aug 11, 2016 at 17:28
5
\$\begingroup\$

Mathematica/Wolfram Language, 28 bytes

Date[][[1]]-#&/@Range[0,120]
\$\endgroup\$
4
  • \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ Commented Aug 11, 2016 at 13:13
  • 4
    \$\begingroup\$ Welcome to PPCG! You don't need to use a map here since subtraction is threaded over lists automatically. And -Range@121+1 saves a byte over the zero-based list. And #&@@ a byte over [[1]]. That said, unless stated otherwise in the challenge, all submissions have to be functions or full programs, and this code is merely a snippet/expression. The shortest fix would be making it an unnamed function by appending &. \$\endgroup\$ Commented Aug 11, 2016 at 13:38
  • \$\begingroup\$ @MartinEnder Thanks for the feedback! I should have caught Minus being list able, minor mental lapse, but the other tips are much appreciated! \$\endgroup\$
    – ktm
    Commented Aug 12, 2016 at 18:13
  • \$\begingroup\$ #&@@Date[]-#&/@0~Range~120& will save you two bytes, but then making it a function requires adding the & on the end (which I think yours needs anyway), so -1 byte in total. \$\endgroup\$ Commented Jul 12, 2017 at 9:05
5
\$\begingroup\$

R, 47 39 bytes

as.double(substr(Sys.Date(),1,4))-0:120

If only someone invented a UTF-8 implementation of R with conveniently abbreviated frequently used system functions...

UPD: shaved off 7 (!) bytes owing to plannapus, who suggested subrtacting a 0:120 vector rather than counting from a to (a-120) and 1 byte grâce à user5957401, who noticed that double would work as well as numeric. Old version:

a=as.numeric(format(Sys.Date(),"%Y"));a:(a-120)
\$\endgroup\$
2
  • \$\begingroup\$ Fiddling around with and seq(a<-...,a-120) can only worsen the situation. \$\endgroup\$ Commented Aug 11, 2016 at 12:48
  • \$\begingroup\$ using the type forcing command as.double instead of as.numeric will save you a byte. Similarly, if instead of formatting a date, you treat the date response as a string to pull from and use substr(Sys.Date(),1,4) you save another byte \$\endgroup\$ Commented Aug 11, 2016 at 14:34
5
\$\begingroup\$

MATL, 10 bytes

1&Z'0:120-

Try it online!

1&Z'      % Push first component of "clock" vector, which is year
0:120     % Literal vector [0, 1, 2, ..., 120]
-         % Subtract element-wise. Implicitly display
\$\endgroup\$
5
\$\begingroup\$

05AB1E, 9 bytes

121FžgN-=

Try online

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Welcome to the site! :) \$\endgroup\$
    – DJMcMayhem
    Commented Apr 3, 2017 at 18:57
4
\$\begingroup\$

php, 73 66 58 42 bytes

<?=implode(', ',range($j=date(Y),$j-120));

Output:

2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009, 2008, 2007, 2006, 2005, 2004, 2003, 2002, 2001, 2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981, 1980, 1979, 1978, 1977, 1976, 1975, 1974, 1973, 1972, 1971, 1970, 1969, 1968, 1967, 1966, 1965, 1964, 1963, 1962, 1961, 1960, 1959, 1958, 1957, 1956, 1955, 1954, 1953, 1952, 1951, 1950, 1949, 1948, 1947, 1946, 1945, 1944, 1943, 1942, 1941, 1940, 1939, 1938, 1937, 1936, 1935, 1934, 1933, 1932, 1931, 1930, 1929, 1928, 1927, 1926, 1925, 1924, 1923, 1922, 1921, 1920, 1919, 1918, 1917, 1916, 1915, 1914, 1913, 1912, 1911, 1910, 1909, 1908, 1907, 1906, 1905, 1904, 1903, 1902, 1901, 1900, 1899, 1898, 1897, 1896

If we don't need to separate with ,, then 58 57 41 bytes:

<?=implode(' ',range($j=date(Y),$j-120));

Thanks to insertusernamehere for saving 16 bytes

\$\endgroup\$
8
  • \$\begingroup\$ You don't really need to separate with ,, look at many of the other answers. \$\endgroup\$ Commented Aug 11, 2016 at 13:25
  • \$\begingroup\$ It looks that way, but I'll put in two options so I can do what most are, and also what was requested \$\endgroup\$
    – gabe3886
    Commented Aug 11, 2016 at 13:27
  • \$\begingroup\$ I've managed to get the comma answer down to my original non-comma answer size. That's as much as I think I can golf it \$\endgroup\$
    – gabe3886
    Commented Aug 11, 2016 at 13:29
  • \$\begingroup\$ You can remove the <?php tag since we allow running with -r for free \$\endgroup\$ Commented Aug 11, 2016 at 13:38
  • 2
    \$\begingroup\$ Golf off 16 bytes: <?=implode(', ',range($j=date(Y),$j-120)); \$\endgroup\$ Commented Aug 11, 2016 at 15:14
4
\$\begingroup\$

Python 2, 64 62 54 bytes

import time
n=time.gmtime()[0]
exec'print n;n-=1;'*121

@KarlKastor thanks for 8 bytes!

\$\endgroup\$
3
  • \$\begingroup\$ time.gmtime().tm_year is 3 bytes shorter \$\endgroup\$
    – KarlKastor
    Commented Aug 11, 2016 at 17:21
  • \$\begingroup\$ time.gmtime()[0] even shorter \$\endgroup\$
    – KarlKastor
    Commented Aug 11, 2016 at 17:27
  • \$\begingroup\$ @KarlKastor nice! Playing with the time module is like walking into a maze every time for me. So many ways to get lost \$\endgroup\$ Commented Aug 11, 2016 at 17:44
4
\$\begingroup\$

PostgreSQL, 57 bytes

Who needs a FROM :-). Probably shouldn't work, but it does, try it at sqlfiddle

select date_part('y',current_date)-generate_series(0,120)
\$\endgroup\$
4
\$\begingroup\$

Bash on OS X, 23

jot 121 `date +%Y` - -1

This will also work on Linux if you have BSD jot installed (e.g. sudo apt-get install athena-jot.

\$\endgroup\$
3
\$\begingroup\$

Python 2, 62 bytes

import time
for n in range(121):print int(time.ctime()[-4:])-n

And at 64 bytes:

for n in range(121):print int(__import__("time").ctime()[-4:])-n
\$\endgroup\$
3
\$\begingroup\$

Oracle SQL 11.2, 111 bytes

SELECT LISTAGG(TO_CHAR(SYSDATE,'YYYY')-LEVEL+1,', ')WITHIN GROUP(ORDER BY LEVEL)FROM DUAL CONNECT BY LEVEL<122;
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I would be tempted to say the the listagg isn't required and just the set of ordered rows \$\endgroup\$
    – MickyT
    Commented Aug 11, 2016 at 20:20
3
\$\begingroup\$

Processing, 51 42 41 bytes

for(int i=0;i<121;)print(year()-i+++" ");

Ungolfed

for(int i = 0; i < 121;)
    print(year() - i++ + " ");

Processing is just a wrapper for Java if you didn't know, and takes most of the boilerplate away, so the obvious solution is also super short compared to a Java version. Also opens a window for drawing graphics, but having that doesn't appear to disqualify me :)

\$\endgroup\$
2
  • 1
    \$\begingroup\$ for(int i=0;i<121;)print(year()-i+++" "); \$\endgroup\$
    – Leaky Nun
    Commented Aug 11, 2016 at 16:27
  • \$\begingroup\$ I love the "+++", it looks so suspicious. Thanks for the suggestion! \$\endgroup\$
    – Cody
    Commented Aug 11, 2016 at 16:38
3
\$\begingroup\$

MATLAB, 18 bytes

Assuming the output format doesn't matter (aside form descending order), the following program prints the last 121 years starting with the current one.

year(date)-(0:120)

It requires MATLAB version r2014a or higher. Earlier versions didn't include the year function.

\$\endgroup\$
3
\$\begingroup\$

JavaScript, 55 52 50 49 bytes

for(a=d=s=Date().substr(11,4);d-->s-120;)a+=" "+d

+9 bytes to alert the data (not necessary if you run this in a console).

for(a=d=s=Date().substr(11,4);d-->s-120;)a+=" "+d;alert(a)

-4 bytes if the delimiter isn't necessary.

for(a=d=s=Date().substr(11,4);d-->s-120;)a+=d

for (a = d = s = Date().substr(11, 4); d --> s - 120; )
    a += " " + d;
console.log(a);

\$\endgroup\$
3
  • 1
    \$\begingroup\$ The []s appear to be unnecessary. \$\endgroup\$
    – Neil
    Commented Aug 11, 2016 at 22:48
  • \$\begingroup\$ @Neil: Thanks. My original solution used an array, but I hadn't thought to remove it. \$\endgroup\$
    – Yay295
    Commented Aug 12, 2016 at 0:26
  • 1
    \$\begingroup\$ You can save one byte using a for instead of while on this: for(a=d=s=Date().substr(11,4);d-->s-120;)a+=" "+d! \$\endgroup\$ Commented Aug 12, 2016 at 7:58
3
\$\begingroup\$

C, 87 85 76 74 65 bytes

main(int i,char**v){for(i=0;i<121;printf("%d,",atoi(v[1])-i++));}

Ungolfed:

main(int i,char**v){
    for(i = 0; i < 121; printf("%d,", atoi(v[1])-i++));
}

My first code golf - Any pointers would be well received. Would be nice if I could cut out the argc/argv junk, but I'm not that skilled a C programmer. Improvements welcome.

EDIT: The current year is obtained from the commandline - specifically by a group of automated, well trained drinking birds.

EDIT 2: 85 bytes Thanks to Easterly Irk (removed spaces around arg function parameters)

EDIT 3: 76 bytes Thanks to anatolyg for pointing out the obvious (removed verbose argc/argv param names)

EDIT 4: 74 bytes Thanks to Yay295 (char**v, changed year delimiter)

EDIT 5: 65 bytes thanks to Yay295 and matt (re-used the variable i, removed variable x, changed while to for loop, updated printf to include atoi() read and i++)

\$\endgroup\$
9
  • 1
    \$\begingroup\$ Can't you a space? int argc, char -> int argc,char? \$\endgroup\$
    – Riker
    Commented Aug 11, 2016 at 16:01
  • 2
    \$\begingroup\$ Replace argc by c (or better replace int argc by just int) and argv by v. Also replace while by for. The latter change requires some experience in C (but may be fun regardless). \$\endgroup\$
    – anatolyg
    Commented Aug 11, 2016 at 17:11
  • 1
    \$\begingroup\$ char*v[] -> char**v saves 1 byte. You can save another by delimiting your years with a space or a comma instead of a newline. \$\endgroup\$
    – Yay295
    Commented Aug 11, 2016 at 17:57
  • 1
    \$\begingroup\$ You can make it shorter. 71 bytes. main(int c,char**v){int i=0;while(i<120)printf("%d,",atoi(v[1])-i++);} \$\endgroup\$
    – hookenz
    Commented Aug 11, 2016 at 20:57
  • 2
    \$\begingroup\$ Even shorter. 65 bytes main(int i,char**v){for(i=0;i<121;printf("%d,",atoi(v[1])-i++));} \$\endgroup\$
    – hookenz
    Commented Aug 12, 2016 at 2:07
3
\$\begingroup\$

JavaScript, 60 53 48 Bytes

f=x=>x>Date().split` `[3]-121&&(alert(x),f(x-1))

I used a recursive solution.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You can replace console.log with alert, and remove the last ;. \$\endgroup\$ Commented Aug 12, 2016 at 22:09
  • 1
    \$\begingroup\$ Save 5 bytes with f=x=>x>Date().split" "[3]-121&&(alert(x),f(x-1)), replacing the quotation marks with backticks. \$\endgroup\$
    – Shaggy
    Commented Apr 20, 2017 at 13:24
3
\$\begingroup\$

Go, 71 bytes

import."time"
func f(){for t,i:=Now().Year(),0;i<120;i++{println(t-i)}}

Attempt This Online!

Prints to STDERR.

\$\endgroup\$
2
\$\begingroup\$

Perl, 33 bytes

say+(gmtime)[5]-$_+1900for 0..120

Run with -M5.010 or -E :

perl -E 'say+(gmtime)[5]-$_+1900for 0..120'
\$\endgroup\$
2
\$\begingroup\$

k, 27 bytes

Output as specified

1@", "/:$(`year$.z.d)-!121;

Example:

k)1@", "/:$(`year$.z.d)-!121;
2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009, 2008, 2007, 2006, 2005, 2004, 2003, 2002, 2001, 2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981, 1980, 1979, 1978, 1977, 1976, 1975, 1974, 1973, 1972, 1971, 1970, 1969, 1968, 1967, 1966, 1965, 1964, 1963, 1962, 1961, 1960, 1959, 1958, 1957, 1956, 1955, 1954, 1953, 1952, 1951, 1950, 1949, 1948, 1947, 1946, 1945, 1944, 1943, 1942, 1941, 1940, 1939, 1938, 1937, 1936, 1935, 1934, 1933, 1932, 1931, 1930, 1929, 1928, 1927, 1926, 1925, 1924, 1923, 1922, 1921, 1920, 1919, 1918, 1917, 1916, 1915, 1914, 1913, 1912, 1911, 1910, 1909, 1908, 1907, 1906, 1905, 1904, 1903, 1902, 1901, 1900, 1899, 1898, 1897, 1896

It can be shortened more by not formatting the output and merely returning the list of integers:

(`year$.z.d)-!121
\$\endgroup\$
2
\$\begingroup\$

jq, 46 characters

(45 characters code + 1 character command line option)

now|strftime("%Y")|tonumber|range(.;.-121;-1)

Sample run:

bash-4.3$ jq -n 'now|strftime("%Y")|tonumber|range(.;.-121;-1)' | head
2016
2015
2014
2013
2012
2011
2010
2009
2008
2007

On-line test

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.