Live data from Hacker News

22-11-22 22:11:22

news.ycombinator.com

11–20 of 40 posts

Re: 22-11-22 22:11:22

#11

Earlier quoted context omitted.

...or last year, on Nov. 12th.

or 11-11-11 11:11:11 or 01-01-01 10:10:10 Interview question: write a program to list them all!

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

Re: 22-11-22 22:11:22

#12
Unix time 1666666666 happened last month, on October 25th 02:57:46 UTC.

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.

Re: 22-11-22 22:11:22

#13
post #8

Earlier quoted context omitted.

or 11-11-11 11:11:11 or 01-01-01 10:10:10 Interview question: write a program to list them all!

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!

Looks like it would be defeated by the dreaded leap second.

Re: 22-11-22 22:11:22

#14
post #8

Earlier quoted context omitted.

or 11-11-11 11:11:11 or 01-01-01 10:10:10 Interview question: write a program to list them all!

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!

Some 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 :)

Re: 22-11-22 22:11:22

#15
post #8

Earlier quoted context omitted.

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!

Looks like it would be defeated by the dreaded leap second.

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.

[1] https://www.bipm.org/documents/20126/64811223/Resolutions-20...

Re: 22-11-22 22:11:22

#16
post #8

Earlier quoted context omitted.

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!

Some 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 :)

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!

Re: 22-11-22 22:11:22

#17
post #16

Earlier quoted context omitted.

Some 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 :)

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!

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

Re: 22-11-22 22:11:22

#18
post #8

Earlier quoted context omitted.

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!

Looks like it would be defeated by the dreaded leap second.

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

Re: 22-11-22 22:11:22

#19
post #16

Earlier quoted context omitted.

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!

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

Post reply on HN