| Bytes | Lang | Time | Link |
|---|---|---|---|
| 028 | Excel | 250820T182135Z | Engineer |
| 055 | Python 3 | 250819T160852Z | Toby Spe |
| 061 | Tcl | 170802T164903Z | sergiol |
| 040 | Lua | 230613T223946Z | bluswimm |
| 024 | Arturo | 230613T220114Z | chunes |
| 006 | Thunno 2 | 230613T182759Z | The Thon |
| 024 | jq n | 221120T001108Z | pmf |
| 045 | Julia 1.0 | 221116T225028Z | Ashlin H |
| 030 | Factor | 221014T022416Z | chunes |
| 049 | Minim | 221014T020946Z | Christia |
| nan | 221013T135108Z | bigyihsu | |
| 012 | K ngn/k | 221013T134710Z | oeuf |
| 009 | Vyxal | 221013T090338Z | DialFros |
| 017 | Fourier | 160811T210456Z | Beta Dec |
| 031 | VBA | 170802T210047Z | Taylor R |
| 048 | JavaScript | 160812T215918Z | Huntro |
| 071 | JavaScript | 170711T140916Z | maracuja |
| 019 | TIBasic | 170405T151022Z | Timtech |
| 065 | JavaScript ES6 | 160811T131027Z | Christia |
| 057 | Groovy | 170420T171227Z | staticme |
| 049 | VBA | 170420T180544Z | Stupid_I |
| 051 | JavaScript ES6 | 170403T115809Z | Shaggy |
| 006 | Japt | 170404T185040Z | Oliver |
| 033 | QBIC | 170404T194418Z | steenber |
| 009 | 05AB1E | 170403T185342Z | P. Knops |
| 076 | C# | 160822T131545Z | TheLetha |
| 054 | Python 3 | 160822T093543Z | shooqie |
| 080 | SQLite | 160812T081210Z | CL. |
| 129 | LaTeX | 160816T060123Z | MH. |
| nan | Ruby | 160812T162329Z | Leibrug |
| 033 | PHP | 160812T191438Z | Alex How |
| 029 | Coffeescript | 160812T221753Z | user3080 |
| 029 | Vim | 160812T145324Z | Captain |
| 059 | Javascript | 160812T094455Z | Dylan Me |
| 065 | C | 160811T155901Z | schil227 |
| 049 | JavaScript | 160811T143443Z | Yay295 |
| 046 | jq | 160812T110032Z | manatwor |
| 113 | Python 2 | 160812T084708Z | Yousef. |
| 133 | C# DotNet core | 160812T090625Z | Hywel Re |
| 125 | Haskell | 160812T074456Z | HEGX64 |
| 010 | MATL | 160811T125557Z | Luis Men |
| 023 | Bash on OS X | 160812T000120Z | Digital |
| 067 | Batch | 160811T225149Z | Neil |
| 039 | R | 160811T124315Z | Andre |
| 033 | BASH + coreutils | 160811T122931Z | Joe |
| 060 | Nim | 160811T211933Z | Copper |
| 027 | k | 160811T190059Z | skeevey |
| 057 | PostgreSQL | 160811T202529Z | MickyT |
| 071 | ListSharp | 160811T200041Z | downrep_ |
| 097 | HP50g RPL | 160811T174140Z | Caleb Pa |
| 018 | MATLAB | 160811T191337Z | Tom Carp |
| 011 | CJam | 160811T140425Z | Business |
| 054 | Python 2 | 160811T121144Z | atlasolo |
| 018 | Vitsy + *sh | 160811T130406Z | Addison |
| 067 | Python 2 | 160811T144206Z | TheIniti |
| 041 | Processing | 160811T161736Z | Cody |
| 054 | VBA | 160811T160051Z | Mathieu |
| 042 | php | 160811T125335Z | gabe3886 |
| 111 | Oracle SQL 11.2 | 160811T153246Z | Jeto |
| 006 | Pyke | 160811T144317Z | Blue |
| 062 | Python 2 | 160811T134228Z | Daniel |
| 010 | Dyalog APL | 160811T115721Z | Adá |
| 074 | Java | 160811T140021Z | Linnea G |
| 034 | R | 160811T134124Z | plannapu |
| 008 | Pyth | 160811T122311Z | Denker |
| 024 | PowerShell | 160811T122237Z | Tessella |
| 028 | Mathematica/Wolfram Language | 160811T131317Z | ktm |
| 036 | Ruby | 160811T125919Z | Seims |
| 007 | 05AB1E | 160811T121649Z | Adnan |
| 033 | Perl | 160811T122400Z | Dada |
| 274 | AngularJS + Lodash | 160811T125419Z | YOU |
Excel, 28 bytes
=YEAR(NOW())-ROW(1:121)+1
YEAR(NOW())returns the year part of the current date & time.ROW(1:121)creates an array of values from1to121.YEAR(~)-ROW(~)+1subtracts that array of values from the current year and then shifts the results up by 1 to correct the list, accounting for howROW(1:121)is 1-indexed.
The results are output as an array of cells.
Lua, 40 bytes
for i=0,120 do print(~~os.date"%Y"-i)end
The ~~ is used to remove a trailing .0 from each year.
Arturo, 24 bytes
$=>[y:now\year y..y-120]
$=>[ ; a function
y:now\year ; assign current year to y
y..y-120 ; the range y down to y-120
] ; end function
Thunno 2, 6 bytes
kOṇÞL-
Explanation
kOṇÞL- # Full program
kO # Push the current year
ṇÞ # Compressed integer 121
L # Lowered range
- # Subtract
# Implicit output
Julia 1.0, 46 45 bytes
using Dates
y=year(now())
show([y:-1:y-120;])
- -1 byte thanks to @amelies: replace
printwithshow
Factor, 30 bytes
[ now year>> dup 120 - [a,b] ]
now ! T{ timestamp { year 2022 } { month 10 } ... etc }
year>> ! 2022
dup ! 2022 2022
120 ! 2022 2022 120
- ! 2022 1902
[a,b] ! { 2022 2021 2020 ... 1902 }
Minim, 49 Bytes
Program is run as follows:
C:\Users\chris> minim -f golf.min
Golfed:
[]="xyear".\<1.\>[1].#<[1]--i.$<32._^!--[0].C-=4.
With whitespace and comments:
[] = "xyear". ; Insert the string 'xyear' into memory from index 0 \
The 'x' character corresponds to the value '120'
\< 1. ; Insert 1 as a system call argument \
This corresponds to the index in memory of the \
function name to call, 'year'
\> [1]. ; Call the function and insert the result at memory index 1
#< [1]--i. ; Print memory index 1 as an integer, post-decremented
$< 32. ; Print a space
_^ !--[0]. ; Skip the next statement if memory index 0, pre-decremented, is 0
C -= 4. ; Subtract 4 from the program counter
Go, 71 bytes
import."time"
func f(){for t,i:=Now().Year(),0;i<120;i++{println(t-i)}}
Prints to STDERR.
K (ngn/k), 12 bytes (Non-competitive)
{x,x-1+!120}
K lacks any date-related functions, so this one is non-competitive.
Explanations:
{x,x-1+!120} Main function. Takes x as input
!120 Generate a range from 0 to 120 (exclusive)
1+ +1 to each number (1..120)
x- x subtract to each number (x-1..x-120)
x, Concat x itself as the first number of the array (x,x-1..x-120)
Fourier, 17 bytes
121(5d-io10ai^~i)
Since no output format is specified, each year is separated by a newline:
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
JavaScript, 60 53 48 Bytes
f=x=>x>Date().split` `[3]-121&&(alert(x),f(x-1))
I used a recursive solution.
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);
TI-Basic, 22 19 bytes
max(getDate:seq(I,I,Ans,Ans-120,~1
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.
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
VBA 49 bytes
a=year(now):for i=a to a-120 step-1:msgbox i:next
JavaScript (ES6), 66 54 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}
Japt, 12 6 bytes
Saved 6 bytes thanks to @ETHproductions
#yonKi
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)
QBIC, 33 bytes
A=right$(_D,4)┘[!A!,!A!-120,-1|?a
C#, 83 76 bytes
n=>{for(n=0;n<121;)System.Console.Write(System.DateTime.Now.Year-n+++" ");};
Python 3, 54
import time
print(*range(time.gmtime()[0],0,-1)[:121])
SQLite, 82 80 bytes
with b(y)as(select strftime('%Y')union select y-1 from b limit 121)select*from b
(For ANSI SQL, replace the strftime() with extract(year from current_date).)
(2 bytes saved thanks to @MickyT)
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 :) ):
Ruby, 47 40 39 bytes
p [*0..Time.new.year].last(121).reverse
Thanks to @Value Ink for 7 bytes!
Ideone link: https://ideone.com/yRovUl
PHP, 40 35 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]
Coffeescript, 29 bytes
->a=Date()[11..14];[a..a-120]
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
Javascript: 68 82 59 bytes
i=121;while(i--){x[i]=Date().substr(11,4)-i;}console.log(x)
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++)
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);
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
Python 2, 113 bytes
import datetime
theYear = datetime.datetime.now()
for i in range(theYear.year, theYear.year-121, -1):
print i,','
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.
Haskell 125 bytes
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
MATL, 10 bytes
1&Z'0:120-
1&Z' % Push first component of "clock" vector, which is year
0:120 % Literal vector [0, 1, 2, ..., 120]
- % Subtract element-wise. Implicitly display
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.
Batch, 67 bytes
@set/ay=%date:~-4%,z=y-120
@for /l %%i in (%y%,-1,%z%)do @echo %%i
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)
BASH + coreutils, 35 33 bytes
x=`date +%Y`;seq $x -1 $((x-120))
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.
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
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)
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!!
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:
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.
CJam, 14 12 11 bytes
Saved 2 bytes thanks to Sp3000 and 1 byte thanks to Martin Ender
et0=121,f-p
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
Python 2, 64 62 54 bytes
import time
n=time.gmtime()[0]
exec'print n;n-=1;'*121
@KarlKastor thanks for 8 bytes!
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.
Python 2, 67 bytes
from datetime import*;for i in range(121):print date.today().year-i
Thanks to Sp3000 for removing one byte
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 :)
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
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
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;
Pyke, 6 bytes
wC7m-
w - 121
m- - for i in range(^):
C7 - current_year-i
(After w, the codepoint for 153 is present but it isn't printable)
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
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]
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.
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
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.
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!
Old 9-byte solution:
_>121S.d3
Builds the range [1...<current year>] and only takes the last 121 elements of it.
PowerShell, 26 24 bytes
@TimmyD improved version:
0..120|%{(date).Year-$_}
Was:
($d=(date).year)..($d-120)
where date runs Get-Date
Mathematica/Wolfram Language, 28 bytes
Date[][[1]]-#&/@Range[0,120]
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.
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!.
Perl, 33 bytes
say+(gmtime)[5]-$_+1900for 0..120
Run with -M5.010 or -E :
perl -E 'say+(gmtime)[5]-$_+1900for 0..120'
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



