7 ms·
I wonder if there was a single person in 1922 that had the same thought.
by coding123 4y ago
I wonder if there was a single person in 1922 that had the same thought.
- 31337Logic 4y ago...or last year, on Nov. 12th.
- quickthrower2 4y agoor 11-11-11 11:11:11 or 01-01-01 10:10:10 Interview question: write a program to list them all!
- carl_dr 4y agoSounds 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!
- lcnPylGDnU4H9OF 4y agoLooks like it would be defeated by the dreaded leap second.
- SAI_Peregrinus 4y agoThey'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. [1] https://www.bipm.org/documents/20126/64811223/Resolutions-2022.pdf/281f3160-fc56-3e63-dbf7-77b76500990f https://www.bipm.org/documents/20126/64811223/Resolutions-20...
- carl_dr 4y agoI don't think so. It would be only year 2006 (which map to second 60) which could be a problem, and there wasn't a leap year in that year.
- AkshatJ27 4y agoSome saves: `Rational(d,86400)` -> `d/86400r` 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 :)
- carl_dr 4y agoruby -e 'require"date";(0..4e9).each{b=DateTime.new(0,1,1)+_1/86400r;c=b.strftime("%y%m%d%H%M%S");puts b.strftime("%y-%m-%d %H:%M:%S")if c==c.reverse}' 151 bytes (including the ruby -e, down from 174.) Thanks!
- AkshatJ27 4y ago`ruby -e 'require"date";0.upto(4e9){b=DateTime.new(0,1,1)+_1/86400r;c=b.strftime"%y%m%d%H%M%S";p b.strftime"%y-%m-%d %H:%M:%S"if c==c.reverse}'` 142? Sorry if I broke anything, on phone.
- carl_dr 4y agoYou 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. Edit: DateTime.new(0) seems to work. 141.
- PinkMilkshake 4y agoPowerShell 7, 108 chars 0..2e9|%{date(date 0).AddSeconds($_)-f 'yy-MM-dd HH:mm:ss'}|?{$_-match'(.)(.)-(.)(.)-(.)(.) \6\5:\4\3:\2\1'}
- yamtaddle 4y ago> write a program to list them all! 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.
- quickthrower2 4y agowhile(1) {} is the universal program to do anything. You can then optimise performance later. Interestingly in Haskell the only pure program of type variable “a” where a means any type at all is the one that never quits: myProg: a myProg = myProg Which amounts to the same thing: it can do anything - produce any type - but it takes literally forever.
- deleted 4y ago[deleted]