Hacker News new | ask | show | jobs
by carl_dr 1299 days ago
ruby -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!

1 comments

`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.

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.

Edit: DateTime.new(0) seems to work. 141.

~~`b=DateTime.new(0,1,1)+_1/86400r;`-> `b=_1/86400r+DateTime.new 0`~~ oops
ruby -rdate -e'b=DateTime.new 0;loop{b+=1/86400r;c=b.strftime"%y%m%d%H%M%S";puts b.strftime"%y-%m-%d %H:%M:%S"if c==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!

That doesn't work unfortunately, you need the brackets - DateTime has to be on the left.
ah, my bad.

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}'`