# List of possible birth years of living humans

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 the output would be

2016, 2015, ..., 1897, 1896

When run next year 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.
• 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). – trichoplax Aug 11 '16 at 11:31
• 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. – trichoplax Aug 11 '16 at 11:33
• Jeanne Louise Calment lived 122 years. – Zenadix Aug 11 '16 at 15:32
• Lad, that was way too early of an accept. – Addison Crump Aug 11 '16 at 17:30
• 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. – CompuChip Aug 14 '16 at 9:58

## 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)

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

# Pyth, 119 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.

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

# 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.

• This is awesome. I did not know it could typecast a string into a number when using the : operator... – Andreï Kostyrka Aug 11 '16 at 22:27

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 # BASH + coreutils, 35 33 bytes x=date +%Y;seq$x -1 $((x-120))  • in your case, quotes are unneeded: change : date +"%Y" into date +%Y – Olivier Dulac Aug 11 '16 at 16:26 • x=date +%Y;seq$x -1 $[x-120] or seq$[x=date +%Y] -1 $[x-120] works as well. – Dennis Aug 11 '16 at 17:48 • 10 bytes shorter if you have OSX or are willing to install jot on Linux – Digital Trauma Aug 12 '16 at 0:11 # CJam, 1412 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  # 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: • Edited answer to get the current year from the calculator. – Caleb Paul Aug 11 '16 at 19:41 # 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!. # PowerShell, 26 24 bytes @TimmyD improved version: 0..120|%{(date).Year-$_}


Was:

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


where date runs Get-Date

• 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. – Joey Aug 11 '16 at 14:35
• 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. – Bevo Aug 13 '16 at 1:04
• @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. – TessellatingHeckler Aug 13 '16 at 1:11

# 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!

# Vitsy + *sh + JavaScript, 332621 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.

• 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. – Caleb Aug 11 '16 at 16:13
• @Caleb Perfect, thanks! Made the need for a JS eval non-existent as well. – Addison Crump Aug 11 '16 at 17:28

Mathematica/Wolfram Language, 28 bytes

Date[][[1]]-#&/@Range[0,120]

• Welcome to PPCG! – Addison Crump Aug 11 '16 at 13:13
• 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 &. – Martin Ender Aug 11 '16 at 13:38
• @MartinEnder Thanks for the feedback! I should have caught Minus being list able, minor mental lapse, but the other tips are much appreciated! – ktm Aug 12 '16 at 18:13
• #&@@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. – numbermaniac Jul 12 '17 at 9:05

## 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)

• Fiddling around with and seq(a<-...,a-120) can only worsen the situation. – Andreï Kostyrka Aug 11 '16 at 12:48
• 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 – user5957401 Aug 11 '16 at 14:34

# 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


# 05AB1E, 9 bytes

121FžgN-=

Try online

• Welcome to the site! :) – James Apr 3 '17 at 18:57

# 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

• You don't really need to separate with ,, look at many of the other answers. – Addison Crump Aug 11 '16 at 13:25
• It looks that way, but I'll put in two options so I can do what most are, and also what was requested – gabe3886 Aug 11 '16 at 13:27
• 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 – gabe3886 Aug 11 '16 at 13:29
• You can remove the <?php tag since we allow running with -r for free – Business Cat Aug 11 '16 at 13:38
• Golf off 16 bytes: <?=implode(', ',range($j=date(Y),$j-120)); – insertusernamehere Aug 11 '16 at 15:14

## Python 2, 64 62 54 bytes

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


@KarlKastor thanks for 8 bytes!

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

# 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)


# 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.

## 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


# 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;

• I would be tempted to say the the listagg isn't required and just the set of ordered rows – MickyT Aug 11 '16 at 20:20

# Processing, 5142 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 :)

• for(int i=0;i<121;)print(year()-i+++" "); – Leaky Nun Aug 11 '16 at 16:27
• I love the "+++", it looks so suspicious. Thanks for the suggestion! – Cody Aug 11 '16 at 16:38

# 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.

## JavaScript, 555250 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);

• The []s appear to be unnecessary. – Neil Aug 11 '16 at 22:48
• @Neil: Thanks. My original solution used an array, but I hadn't thought to remove it. – Yay295 Aug 12 '16 at 0:26
• 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! – Dom Hastings Aug 12 '16 at 7:58

## C, 87857674 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++)

• Can't you a space? int argc, char -> int argc,char? – Rɪᴋᴇʀ Aug 11 '16 at 16:01
• 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). – anatolyg Aug 11 '16 at 17:11
• 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. – Yay295 Aug 11 '16 at 17:57
• You can make it shorter. 71 bytes. main(int c,char**v){int i=0;while(i<120)printf("%d,",atoi(v[1])-i++);} – Matt Aug 11 '16 at 20:57
• Even shorter. 65 bytes main(int i,char**v){for(i=0;i<121;printf("%d,",atoi(v[1])-i++));} – Matt Aug 12 '16 at 2:07

# JavaScript, 60 53 48 Bytes

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


I used a recursive solution.

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

## Perl, 33 bytes

say+(gmtime)[5]-$_+1900for 0..120  Run with -M5.010 or -E : perl -E 'say+(gmtime)[5]-$_+1900for 0..120'


# 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  # 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

## Vim, 32 29 keystrokes

Thanks to @daniero for some help on saving some keystrokes and making the output a little neater.

"=strftime('%Y')<Enter>pqqYp<Ctrl-x>q118@q

• <Enter> is Enter
• <Ctrl-x> is Ctrl + X

### Explanation:

"                                          # Put into the register {
=strftime('%Y')                           #   This year in YYYY form
<Enter>                    # }
p                   # Paste the register
qq                 # Record macro q {
Y                #   Yank (copy) the current line
p               #   Paste
<Ctrl-x>       #   Decrment number at cursor
q      # }
118@q # Do macro q 118 times


### Output format:

Each number is on a separate line like below.

2016
2015
.
.
.
1898
1897

• OP clearly asks for a future-proof version, so only the second one answers the question. Don't you need to punch the Enter key (commonly refered to as <CR> in Vim context) after :pu=strftime('%Y')? Also, you can skip some keystrokes by using Y with copies the whole line. In total: :pu=strftime('%Y')<CR>qqYp<Ctrl-x>q118@q - 30 keystrokes – daniero Aug 12 '16 at 18:35
• Also, you can yank from the = register: "=strftime('%Y')<CR>pqqYp<Ctrl-x>q118@q - 29 keystrokes, and it gets rid of the first empty line – daniero Aug 12 '16 at 18:42
• If you're allowed to use shell as well then you can save five more keystrokes with the date utility: :.!date +\%Y<CR>qqYp<C-x>q118@q` – John Gowers Aug 15 '16 at 10:04