# 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

## PHP, 4035 33 bytes

while($i<121)echo date(Y)-$i++._;


I'm just going to pretend that error reporting is always disabled for code golfing... :)

[Edit 1: Saved 5 bytes via manatwork]

[Edit 2: Saved 2 bytes via Titus]

• Forget good coding habits here. ;) Call that date() 121 times: while($i<121)echo date(Y)-$i++." ";. – manatwork Aug 13 '16 at 11:33
• @manatwork: save another two bytes by using the underscore (or any letter or 0) as separator: while($i<121)echo date(Y)-$i++,_; (33 bytes) – Titus Aug 13 '16 at 12:35
• @manatwork Oh cripes how did I miss that? :) – Alex Howansky Aug 13 '16 at 14:10
• @Titus Nice. I used the "interpret an unquoted constant as a string" thing already once here, and still totally missed this one. – Alex Howansky Aug 13 '16 at 14:18
• It is always assumed that config is at default settings, so in PHP: E_NOTICE, E_DEPRECATED and E_STRICT are off -> You´re safe. (for different settings you have to either add the command or the string to add to config to your byte count) – Titus Aug 13 '16 at 15:59

# LaTeX, 129 bytes

Or, if I'm allowed to skip the document class definition & setup, and just count the package import and for loop code: 79 bytes.

\documentclass{book}\usepackage{tikz}\begin{document}\foreach \n in {0,...,120}{\pgfmathint{\year\n}\pgfmathresult}\end{document}


Ungolfed:

\documentclass{book}
\usepackage{tikz}
\begin{document}
\foreach \n in {0,...,120}
{
\pgfmathint{\year-\n}\pgfmathresult}

\end{document}


Output (w/ free page number :) ):

• You can have this a lot shorter: \input tikz \foreach~in{2020,...,1900}{~ }\bye in Plain TeX. If you insist on doing it in LaTeX, you can save big on leaving out all the calculations... Just go like this: \documentclass{book}\usepackage{tikz}\def~{document}\begin~\foreach~in{2020,...,1900}{~ }\end~. This is only 94 bytes! You can, btw, save another couple of bytes by writing input instead of usepackage... – Joe85AC Jun 5 '20 at 15:59

# Japt, 12 6 bytes

Saved 6 bytes thanks to @ETHproductions

#yonKi


Try it online!

### Explanation:

#yonKi
#y          // # gets the char-code of y, which is 121
o         // Create a range from [0...121]
nKi      // At each item, perform .n(K.i()), which subtracts each item from Ki (Current year)



# Fourier, 17 bytes

## Non competing

I added the date feature (d) earlier today, so this answer is invalid. Despite this, I decided to add this for reference.

121(5d-io10ai^~i)


Since no output format is specified, each year is separated by a newline:

Try it online

### VBA, 54 bytes

In the immediate pane:

For i=0 To 120:?Year(Date)-i &IIf(i=120,"",", ");:Next


In an actual Sub procedure (the VBE adds whitespace and changes ? to Print, but the code is per language specs without the whitespace and using the ? shorthand nonetheless):

Sub A()
For i = 0 To 120: Print Year(Date) - i & IIf(i = 120, "", ", ");: Next
End Sub


That's 88 characters per Notepad++, with i being an undeclared, implicit Variant local variable.

Both produce the output exactly as specified in the question, comma-separated and with a space between each year:

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 the commas aren't a requirement (as some other answers seem to presume), then the IIf part can be dropped, cutting the immediate pane code down to 33 bytes:

For i=0 To 120:?Year(Date)-i:Next


# Python 2, 67 bytes

from datetime import*;for i in range(121):print date.today().year-i


Thanks to Sp3000 for removing one byte

• For future reference: In most situations, __import__ isn't really needed, e.g. here you can do from datetime import* and print date.today().year-i instead for -1 byte. – Sp3000 Aug 11 '16 at 15:01

## ListSharp, 71 bytes

NUMB a=<c#DateTime.Now.Yearc#>
[FOREACH NUMB IN a TO a-120 AS y]
SHOW=y


Uses embedded c# code, new feature!!

# Nim, 60 bytes

import times
for a in 0..120:echo getTime().getGmTime.year-a


Outputs each year on a new line. We use the getTime to get the current UNIX time, then convert it to UTC with getGmTime, get the year minus the counter variable, and echo it.

## Batch, 67 bytes

@set/ay=%date:~-4%,z=y-120
@for /l %%i in (%y%,-1,%z%)do @echo %%i


The imports take up a large part of the byte count

import Data.Time.Clock
import Data.Time.Calendar
main=fmap((\(x,_,_)->[x-120..x]).toGregorian.utctDay)getCurrentTime>>=print

• I'm afraid the list is in the wrong order, the spec says current year first. Howevery we can save a few bytes: a) import Data.Time should be enough for all needed functions. b) use the infix version of fmap, i.e. <$>. c) do x<-toGregorain ... ;print[x-120..x] is shorter than the lambda. d) You can extract the year from getZonedTime via read.take 4.show<$>getZonedTime. All in all, including correct order: import Data.Time;do y<-read.take 4.show<$>getZonedTime;print[y,y-1..y-120]. – nimi Aug 12 '16 at 18:28 # C# - DotNet core - 133 bytes ## Golfed class Program{static void Main(){int x=0,y=System.DateTime.Now.Year;while(x<121){System.Console.Write($"{y-x++}"+(x<121?", ":""));}}}


## Ungolfed

class Program
{
static void Main()
{
int x=0, y=System.DateTime.Now.Year;

while(x<121)
{
System.Console.Write($"{y-x++}" + (x < 121 ? ", " : "")); } } }  ## Output: I'm sure this can be improved. I don't particularly like the if statement to display or hide the trailing comma. ## Javascript: 6882 59 bytes i=121;while(i--){x[i]=Date().substr(11,4)-i;}console.log(x) • Will this give a proper output when run in 2017? – Leibrug Aug 12 '16 at 13:21 • yes, now it will, oops :-) – Dylan Meeus Aug 12 '16 at 14:01 # Coffeescript, 29 bytes ->a=Date()[11..14];[a..a-120] • Welcome to Programming Puzzles & Code Golf! – Dennis Aug 12 '16 at 22:42 • Thanks! I've been lurking for a while, finally had time to start – user3080953 Aug 12 '16 at 23:07 # Ruby, 4740 39 bytes p [*0..Time.new.year].last(121).reverse  Thanks to @Value Ink for 7 bytes! Ideone link: https://ideone.com/yRovUl • Some people are submitting programs where the separator is newline, so you can take out the joining operation and just puts it. Or use p *<the rest> because they're all integers – Value Ink Aug 12 '16 at 19:31 • Thank you @Value Ink. Since outputting an array is allowed, I used plain p instead p *<the rest> – Leibrug Aug 16 '16 at 5:28 # SQLite, 82 80 bytes with b(y)as(select strftime('%Y')union select y-1 from b limit 121)select*from b  SQLFiddle (For ANSI SQL, replace the strftime() with extract(year from current_date).) (2 bytes saved thanks to @MickyT) • You can save yourself a couple with select*from b rather than select y from b – MickyT Aug 21 '16 at 20:57 # Python 3, 54 import time print(*range(time.gmtime()[0],0,-1)[:121])  ## C#, 83 76 bytes n=>{for(n=0;n<121;)System.Console.Write(System.DateTime.Now.Year-n+++" ");};  # JavaScript (ES6), 6654 51 bytes My first foray into code golf so I'm open to suggestions for improvements. The following will output an array of the required years. f= _=>[...Array(121)].map((x,y)=>Date().split [3]-y) console.log(f()); ## History ### 54 bytes _=>Array(121).fill(Date().split [3]).map((x,y)=>x-y)  ### 66 bytes (y=[Date().split [3]],x=121)=>{while(x--)y[x]=(y[0]-x);return y}  • Well done this was my solution before i read any comments _=>[...Array(121)].map((v,i)=>Date().substr(11,4)-i) – James Harrington Nov 26 '17 at 20:32 # JavaScript (ES6), 65 bytes [...Array(1+- -Date().substr(11,4)).keys()].slice(-121).reverse() You're welcome to improve and shorten it... Thanks to @Yay295 for the fix. I was 1 year off. • [...Array(+Date().substr(11,4)).keys()].slice(-120).reverse() is less! – eithed Aug 11 '16 at 14:21 • 56 Bytes in ES5: s='';for(i=120;i--;)s+=new Date().getFullYear()-120+', ' – innovati Aug 11 '16 at 14:40 • @innovati: That prints the same year over and over. If you replace the last '120' with 'i' as I expect you meant, it's still in the wrong order. – Yay295 Aug 11 '16 at 14:46 • @ChristiaanWesterbeek,@eithedog: You're both off by 1. Try [...Array(1+- -Date().substr(11,4)).keys()].slice(-121).reverse() instead. – Yay295 Aug 11 '16 at 15:01 # Java 75 74 bytes public void possible(){ for(int i=0;i<120;){ System.out.println(new Date().getYear()-i++); } }  Golfed : void p(){for(int i=0;i<120;)System.out.println(new Date().getYear()-i++);}  1 byte off. Thanks to @LeakyNun • void p(){for(int i=0;i<120;)System.out.println(new Date().getYear()-i++);} – Leaky Nun Aug 11 '16 at 14:08 • What version of Java is this? As far as I'm aware, getYear() gives you the year since 1900. That means that the current output would be [116, -3]. You'd have to add +1900 (5 bytes) in order to get the correct output. Also, Date requires an import (java.util.Date), which would add to the byte count too. – MH. Aug 11 '16 at 19:41 • @MH. is right, this code will not compile without the imports so you need to either new java.util.Date() or add the import. Also, why don't you shorten it further by replacing the method with a lambda expression? – Shaun Wild Aug 15 '16 at 9:26 ## Python 2, 113 bytes import datetime theYear = datetime.datetime.now() for i in range(theYear.year, theYear.year-121, -1): print i,','  • Welcome to Code Golf! You need to list the language you're using, and because this is a code-golf challenge, you also need the bytecount. – Value Ink Aug 12 '16 at 9:24 • This is definitely Python 2. – user45941 Aug 12 '16 at 9:58 • Thanks. How can I calculate the bytes? – Yousef. Python Aug 12 '16 at 11:02 ## QBIC, 33 bytes A=right$(_D,4)┘[!A!,!A!-120,-1|?a


## VBA 49 bytes

a=year(now):for i=a to a-120 step-1:msgbox i:next


# Groovy, 57 bytes

d=new Date().getYear()+1899;(d​..d-120).each{println it​}


Explanation

d=new Date().getYear()                               //returns how many years have passed since 1900
+1899;                         //adding 1900 will give us the current year, but we want the program to start one year before, so we do +1900-1=1899
(d..d-120)               //a range from the current year -1 to 120 years before that
.each{print it}// for each element in the range, print it.


Output

2016
2015
2014
...
1898
1897
1896


Because of the 1899 trick, it starts with 2016 instead of 2017

Tested on the Groovy Web Console

# TI-Basic, 22 19 bytes

max(getDate:seq(I,I,Ans,Ans-120,~1

• getDate:Ans(1 can be max(getDate. – lirtosiast Jul 11 '17 at 1:43

## JavaScript, 75 71 bytes

Saved 4 bytes thanks to Zachary.

e="";for(y=(new Date).getFullYear(),i=y;i>=y-120;i--)e+=i+" ";alert(e)


Prints all years into a single alert.

I'm sure it could be improved.

## History

75 bytes

var e="";for(y=(new Date).getFullYear(),i=y;i>=y-120;i--)e+=i+" ";alert(e);


(Every year was in a separate alert)

for(y=(new Date).getFullYear(),i=y;i>=y-120;i--)alert(i);

• Welcome to PPCG! I'm not sure whether there exists a consensus on this, but I do not think that opening an alert for each element counts as outputting the list. – Laikoni Jul 11 '17 at 14:29
• Hello. It is now in a single alert. (but with more bytes... :)) – maracuja-juice Jul 11 '17 at 15:31
• Two things, I don't think you need the var before e, and I also don't think you need a semicolon after alert(e). – Zacharý Jul 11 '17 at 19:08

# Tcl, 76 bytes

set y [clock format [clock seconds] -format %Y]
time {puts \$y;incr y -1} 121


Try it online!

# VBA, 31 Bytes

Anonymous VBE immediate window function that takes no input and outputs to the VBE immediate window

For i=0To 120:?Year(Now)-i:Next


### Ruby, 39 36 bytes

t=Time.new.year;t.downto(t-120).to_a


Old:

t=Time.new.year;(t-120..t).to_a.reverse


Should be obvious.

• Where's the output? – daniero Aug 11 '16 at 13:29
• Output is implicit. It's the return value of the last statement. Test it here: repl.it/CmDY/0 – Seims Aug 11 '16 at 13:31
• Output is not implicit: You can print the result, or you can return it from a function. From the codegolf wiki: Both programs and functions may output by writing to STDOUT. Functions may also use their arguments or return value(s) for output. – daniero Aug 11 '16 at 13:56
• I'm sorry to be so strict and boring -- of course i know what you mean, but your answer is sloppy, as it doesn't do anything. All other answers here, as far as I can tell, either prints something or returns something. – daniero Aug 11 '16 at 14:01
• Just do p *t.downto(t-120) :D no proc object needed – Value Ink Aug 11 '16 at 19:27