Archive for the 'linux' Category

XKCD’s Collatz Conjecture

In the XKCD comic dated 3/4/2010, the Collatz Conjecture presents the following scenario:

Well I don’t know if your friends will stop calling your or not, but I was curious about what the graph would actually look like. The graph in the comic looks like it was created with Graphviz, one of my favorite programs!

So I wrote a quick bash script to generate the approrpiate links for graphviz to interpret:

#!/bin/bash
echo "digraph \"xkcd\" {"
for NUMBER in `seq 1 100`
do
 if [ $[$NUMBER % 2] -eq 0 ]; then #We are even
 let OUTPUT=$NUMBER/2
 else  #Odd
 let OUTPUT=$NUMBER*3+1
 fi
 echo "$NUMBER -> $OUTPUT"
done
echo "}"

So what does it really look like? Here:

There are lots of straggling links. This is of course only because I went to 100. Why not 1000? It is a little big… click Here.

Turns out with even more numbers we end up with even more isolated links, no big super chain.

If you would like to run this code for yourself, first make sure you have the graphviz package installed in your linux system. Then copy that code above into a script, say called xkcd.sh. Then run like so:

./xkcd.sh | neato -Tpng | display

Adjust as necessary.

Super Paper Mario – Chapter 2 Graph

My girlfriend plays an interesting Wii game called Super Paper Mario where Mario can shift between a 2-dimensional and a 3-dimensional world. Pretty interesting. In chapter 2 section 4 there is a maze of rooms where one must find the last room, room 10. Of course there are walk-throughs all over the internet, but I had her read to me what room she was in, which door she walked through, and what in what room she emerged. Like this:

“Room 9 BR” -> “Room 5 Top”

This means that Room 9’s Bottom Right door drops you into Room 5’s top door. I inputed all the all of the connections, and let one of my favorite programs, graphviz do the rest!

Using the graphviz mediawiki plugin, all I have to do is input the graph text into a page on my wiki, click save, and it will spit out a graphical version (click to see the full size):

It could use some tweaking for the overlaps, but its pretty good as is if you ask me. It certainly gives you an insight into the developers thinking when creating the maze. This would certainly be very difficult to do on paper and have it come out clean.

Here is the link to my actual wiki article. Feel free to edit the graph and click save to see what change happens. (You will have to create an account. Really feel free, I don’t mind, edit away!)

And if you have some suggestions to make the graph look even better, just make them! I watch the recent changes rss feed and I will see it.

A Car Wreck

Car after Accident

2009-11-19 15.59.05

2009-11-24 16.34.08

This is mostly for my archival purposes.

ToorCamp: Day 1

When I first arrived at toor camp, I was issued a Hardhat and a kit of electronics to construct my own badge:

DCAM0008DCAM0007

What a cool start! Combined with the already cool scenery:

DCAM0001DCAM0005DCAM0012DCAM0016

Only one problem: no silo access. We’ll see if that changes for day two…

Decrypting an eBook to make it Searchable

So I spent $22 on an ebook for school.

It has this crappy DRM that only lets me view the pdf on one computer using only “Adobe Digital Editions”.

If that wasn’t so bad, only a small subset of the text is OCR’d, so most of it isn’t even searchable!

Now I’m pissed, but wait, what do you say? These files are just RSA encrypted, and I have the key?

Some cool guy named i♥cabbages has released code do extract your key, and then decrypt the file to a good ol’ plain pdf. If you want to reproduce my steps you will need to use the PDF decrypter unless you have epubs.

So I use the tool and get a pdf, now I can use one of the most awesome tools in the world: Imagemagick.

Imagemagick can whip this pdf into shape. The first thing I’m going to do is convert each page into a tiff:

$ convert -density 200 input.pdf[1-124] -depth 8 -monochrome %05d.tif

Then I’m going to run tesseract-ocr on them to get the text:

$ for i in $(seq –format=%005.f 1 324)
do
tesseract $i.tif tesseract-$i -l eng
done

Now all I have to do is cat all the text together:

cat *.txt > output.txt

Now I have a fully searchable, plain text file. Exactly what I wanted in the first place!

For the REAL magic, I use agrep to search for strings similar to provided example test questions to help “highlight” the answers. More technical details on that magic on my wiki.

answer