
Reverse-Engineering Xkcd's 'Frequency' - ams1
http://notebooks.jsvine.com/reverse-engineering-xkcd-frequency/
======
deckar01
I am trying to apply the Chinese remainder theorem to solve the time required
for all of the events to occur simultaneously. I am ignoring the GIF timing
bug.

    
    
      1. Normalize times to integers.
      2. Assume congruence at x = t mod (t+1).
      3. Solve congruence system.
      4. Denormalize result.
    

Python solution: [http://ideone.com/Wh2SR6](http://ideone.com/Wh2SR6) Solution
perspective:
[http://www.wolframalpha.com/input/?i=35417600268377072234556...](http://www.wolframalpha.com/input/?i=3541760026837707223455613087881588712157229686722179240978118057837619969343910617190906282246617252766842304240193875476480000000000+seconds)

~~~
oneeyedpigeon
I sometimes wish a HN comment could be 'favourited'.

------
josephwegner
Not super related to the content, but I love the "Show Code" button at the
bottom of the article. So often sites either show code inline and break up my
reading, or just dump the whole thing into a github repo, which loses context.
That button is awesome, because I can read the whole thing to understand the
problem, then review the code the next time through with better context.

Awesome!

~~~
bbx
I agree that having a "Show code" button only at the end prevents disrupting
the reading flow.

In terms of "code with explanation" layout, I really like todos.js' approach:
[http://backbonejs.org/docs/todos.html](http://backbonejs.org/docs/todos.html)

It also works with images:
[http://www.ifixit.com/Teardown/Mac+Pro+Late+2013+Teardown/20...](http://www.ifixit.com/Teardown/Mac+Pro+Late+2013+Teardown/20778)

Most layouts nowadays fail to take advantage of the horizontal space
available. It's just 2 colums in the end, but it goes a long way.

~~~
resu_nimda
The todos.js one was generated by a tool called Docco, created by Jeremy
Ashkenas (creator of Backbone, Underscore, and CoffeeScript). I agree that it
looks really good and more people should use it for their projects!

[http://jashkenas.github.io/docco/](http://jashkenas.github.io/docco/)

~~~
hueving
>created by Jeremy Ashkenas (creator of Backbone, Underscore, and
CoffeeScript)

Just out of curiosity, why did you include that? Do people make judgements
about tools based on the person who wrote it?

~~~
tg3
I'd say yes. If you took the time to independently evaluate every tool that
was ever produced, you wouldn't have time for anything else. So instead,
people rely on crude, biased, but effective heuristics, the author's past
achievements being one of them.

It's the same thing with novel authors - I'm much more likely to purchase a
book by Stephen King than an unknown author's debut album if that's all I know
about the books.

~~~
oneeyedpigeon
In my experience, unknown authors do tend to make terrible debut _albums_ :)

------
nly
For anyone wondering how to dump gif loop time.

    
    
        curl -s http://imgs.xkcd.com/comics/frequency/turnsignal1.gif | 
            giftext | grep DelayTime | cut -d':' -f 2 | awk '{s+=$1} END {print s/100}'
    

The results seem to correspond with authors table.

~~~
maxerickson
Click the show code button at the bottom. They did dump the values (but they
wrote their own gif parser...).

~~~
nly
Ah thanks, I completely missed that button. I just typed 'gif' in to my
terminal and hit tab to see what I had installed, then read the manpage for
the most favourable looking binary

------
ck2
There are some really clever people in this world.

One to make it.

One to take it apart.

------
scelerat
I can't imagine a better followup to an xkcd strip. Bravo.

~~~
BrandonMarc
I was really hoping Munroe himself would publish the data. I'm glad someone
else did, with the helpful explanations.

------
dav-
Awesome, this is one of my favorite XKCDs. I've been mulling over a plan in my
mind to make a physical version of it, looking similar to a deep picture frame
or display case. It would use white acrylic with the text somehow printed or
transferred on, backlit by white LEDs (maybe incandescent lamps would look
nicer?). Each cell would be separated by thin black wood or plastic strips. It
should be pretty easy to control the whole thing with an arduino, and I think
it would make an awesome wall display.

~~~
jsvine
I like this. Reminds me a (tiny) bit of Bruce Nauman's "One Hundred Live and
Die": [http://www.art21.org/images/bruce-nauman/one-hundred-live-
an...](http://www.art21.org/images/bruce-nauman/one-hundred-live-and-die-1984)

~~~
dav-
He's got some... interesting... pieces:
[http://www.youtube.com/watch?v=LDuvLc_FAXE](http://www.youtube.com/watch?v=LDuvLc_FAXE)

------
Dylan16807
What I found interesting was the format of the gifs themselves. They were
mostly or completely uncompressed, totaling 8MB. I can only think of one
possible reason to do this, which would be to take advantage of HTTP
compression to go inter-frame instead of using the builtin intra-frame that
gifs have (.5MB vs 4MB). But HTTP compression was turned off too.

------
arithma
There's more analysis here than reverse engineering. Nice work still.

------
aphrax
I'm still trying to understand where the frequency is stored? Is it a value
that can be embedded into the gif?

~~~
eli
Gifs don't have a constant FPS. You can specify with some precision how long
they should display each frame.

~~~
jsvine
That's right. The Graphic Control Extension blocks preceding each frame let
you specify a "delay" in hundreths of a second.

More info here:
[http://www.matthewflickinger.com/lab/whatsinagif/animation_a...](http://www.matthewflickinger.com/lab/whatsinagif/animation_and_transparency.asp)

And more info on the zero-delay problem here:
[http://nullsleep.tumblr.com/post/16524517190/animated-gif-
mi...](http://nullsleep.tumblr.com/post/16524517190/animated-gif-minimum-
frame-delay-browser-compatibility)

------
roma1n
Didn't get the "A european resident has their first kiss" though. Wouldn't it
make more sense to divide the frequency by two and state "Two european
residents have their first kiss"?

~~~
jeffgreco
It very well may only be one of the participants' first kiss.

~~~
CodeWithCoffee
Or one participant may not be European.

------
guelo
To me the most interesting thing in this article were the urls of the inlined
images, <img src="data:image/png;base64,...> I had no idea you could do that.

~~~
aidos
You can actually use it for all sorts of things. (eg embedded fonts)

[https://en.wikipedia.org/wiki/Data_URI_scheme](https://en.wikipedia.org/wiki/Data_URI_scheme)

------
nextstep
Does anyone know the answer to the "turn signal problem" he poses? Why does
the beat frequency he observes match what he calculated?

~~~
maxerickson
Assuming you meant "doesn't", it's explained in the next section, the Zero-
Delay Problem.

edit: The frequency equation solved for time, using the adjusted values from
the table:
[https://www.google.com/search?q=1%2F%281%2F1-1%2F1.04%29](https://www.google.com/search?q=1%2F%281%2F1-1%2F1.04%29)

~~~
nextstep
Thanks

------
agmartin
I'm completely distracted by the fact that this was #1331.

Surely he must have something truly epic saved up for 1337.

Right? Anyone?

------
kriswill
This page is hard crashing Safari latest on my MBP 2013. Anyone else
experiencing this?

~~~
cocire
yeah, same problem here. safari on a 2013 air starts to load the top of the
page then stops responding... :( seems fine in firefox though

------
ingend88
Get this story in your mailbox with daily newsletter for top 5 HN Post, signup
at [http://top5hn.launchrock.co](http://top5hn.launchrock.co) Stats after
creating the landing page in last 24hours: 944 Page Views 101 Signups
Newsletter Stats 41% Open Rate 40% CTR

