They're going away. Resolution 4 of the CGPM 2022[1]. They didn't want to deal with having to add a negative leap second, and it looks likely they'd have to if they didn't end them.
You need to use puts to avoid quotes being added around the output - so I'll give you 145! I'm on my phone too, I'm impressed I even got something working, you've done brilliantly.
39 comments
[ 2.9 ms ] story [ 99.3 ms ] threador 01-01-01 10:10:10
Interview question: write a program to list them all!
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!
[1] https://www.bipm.org/documents/20126/64811223/Resolutions-20...
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 :)
151 bytes (including the ruby -e, down from 174.) Thanks!
142? Sorry if I broke anything, on phone.
Edit: DateTime.new(0) seems to work. 141.
This should work for 134:
`ruby -r date -e '0.upto(4e9){b=DateTime.new(0)+_1/86400r;puts b.strftime"%y-%m-%d %H:%M:%S"if(c=b.strftime"%y%m%d%H%M%S")==c.reverse}'`
127. Script never terminates, but it does display all possibilities, so I think it still passes!
Edit: 126. ruby -rdate -e'b=DateTime.new 0;loop{b+=1/86400r;puts b.strftime"%y-%m-%d %H:%M:%S"if(c=b.strftime"%y%m%d%H%M%S")==c.reverse}'
I think I'm done for the moment, will revisit tomorrow if you can find any further savings!
Me: Is it OK if it doesn't print until it's done?
Interviewer: Uh, sure, why not?
Me: while(1){}
Me: Finished. This produces the exact desired output of the program you specified.
Interviewer: GTFO.
Interestingly in Haskell the only pure program of type variable “a” where a means any type at all is the one that never quits:
Which amounts to the same thing: it can do anything - produce any type - but it takes literally forever.A closer "round" number will be 1670000000, happening next month on December 2nd 16:53:20 UTC.
But for 1700000000 we'll have to wait until next year, November 14th 22:13:20 2023 UTC.
I've noticed good times like that getting fewer and farther between.