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

1 2
3
0
\$\begingroup\$

TI-Basic, 22 19 bytes

max(getDate:seq(I,I,Ans,Ans-120,~1
\$\endgroup\$
1
  • \$\begingroup\$ getDate:Ans(1 can be max(getDate. \$\endgroup\$
    – lirtosiast
    Commented Jul 11, 2017 at 1:43
0
\$\begingroup\$

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);
\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$
    – Laikoni
    Commented Jul 11, 2017 at 14:29
  • \$\begingroup\$ Hello. It is now in a single alert. (but with more bytes... :)) \$\endgroup\$ Commented Jul 11, 2017 at 15:31
  • \$\begingroup\$ 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). \$\endgroup\$
    – Adalynn
    Commented Jul 11, 2017 at 19:08
0
\$\begingroup\$

Tcl, 76 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

Factor, 30 bytes

[ now year>> dup 120 - [a,b] ]

Try it online!

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 }
\$\endgroup\$
0
\$\begingroup\$

jq -n, 24 bytes

now|gmtime[0]-range(121)

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Arturo, 24 bytes

$=>[y:now\year y..y-120]

Try it!

$=>[           ; a function
    y:now\year ; assign current year to y
    y..y-120   ; the range y down to y-120
]              ; end function
\$\endgroup\$
0
\$\begingroup\$

Lua, 40 bytes

for i=0,120 do print(~~os.date"%Y"-i)end

Try it online!

The ~~ is used to remove a trailing .0 from each year.

\$\endgroup\$
-1
\$\begingroup\$

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.

\$\endgroup\$
9
  • \$\begingroup\$ Where's the output? \$\endgroup\$
    – daniero
    Commented Aug 11, 2016 at 13:29
  • \$\begingroup\$ Output is implicit. It's the return value of the last statement. Test it here: repl.it/CmDY/0 \$\endgroup\$
    – Seims
    Commented Aug 11, 2016 at 13:31
  • \$\begingroup\$ 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. \$\endgroup\$
    – daniero
    Commented Aug 11, 2016 at 13:56
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – daniero
    Commented Aug 11, 2016 at 14:01
  • 1
    \$\begingroup\$ Just do p *t.downto(t-120) :D no proc object needed \$\endgroup\$
    – Value Ink
    Commented Aug 11, 2016 at 19:27
1 2
3

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.