|
Sounds like a great Code Golf contest. ruby -e 'require"date";a=DateTime.new(0,1,1,0,0,0);(0..4e9).each{|d|b=(a+Rational(d,86400));c=b.strftime("%y%m%d%H%M%S");puts b.strftime("%y-%m-%d %H:%M:%S")if c==c.reverse}' About the most inefficient anyone could make it, but I think it works! |
Get rid of the variable `a` since it is used in only one place.
`DateTime.new(0,1,1,0,0,0)` -> `DateTime.new(0,1,1)`
also in newer ruby versions you can use numbered parameters to replace d with _1 and remove `|d|`
Pretty sure there might be some more which i do not see immediately :)