There was this thread on Hacker News:
Produce the number 2014 without any numbers in your code (stackexchange.com), which in turn came from this question on codegolf.stackexchange.com.
Somewhat silly or at least contrived question, but for fun, using this idea by HN user colomon, I worked out a solution:
import time s = time.ctime() print s[s.rindex(' '):].strip()
The solution uses a total of 64 bytes, or 56 without the .strip(), which is only needed to remove a leading space from the output.
[ Update: A suggestion from HN user colomon to get the year directly (see same HN thread), led to this improved version:
import time print time.localtime()which brings it down to ~40 bytes. ]
There were shorter solutions in Python at the original question page, and some of the shortest were in Python, Ruby, Go and FORTH.
One nice solution in Python was this :-)
print sum(ord(c) for c in 'Happy new year to you!')It actually works.
- Vasudev Ram - Dancing Bison Enterprises