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:
A shout out and big thanks to my friend DangerJim who gave me some sugru to help coat the joysticks of my RC trainsmitter so they don’t hurt my thumbs. The results look pretty nice:
If you play any of these games, feel free to ally with me If aftershock bans me, no big deal
These are the types of games that make you log in often to check your status, and use your energy (otherwise it is wasted). The thing is, most of the decisions and things I do in these games are just to preocupy your time, I could write a program to do the simple things for me. So I did! Now only if I could run it periodically from a cronjob. You see, they require you to type in a CAPTCHA every time you log into the web interface, so for my program to work I have to manually log in first. But wait, the ipod app doesn’t require a captcha… if only I could run the app from the ipod, steal it’s auth cookie, then run my program it could be compeltely automated! Well the best way I could find to do this was to use the T-Plan vnc robot to do the required key presses, then let ssh and bash do the rest.
I also looked into using the Erica Utilities to start the game without the complexity of vnc, but I found they didn’t work on my platform with the 3.0 firmware. So now I can just sit back and let my robot level me up forever!
Here are some more technical details on the script itself if you are interested. Anyone who plays these games would find these features very desireable:
Recovers from raids
Repairs your buildings
Accepts all incoming ally invitations
Automatically uses all your fighting power to get at least 2exp for every fight, and choosing opponents that you can win against. (It automatically heals you if you need it)
Redeems combo/key/spell codes from a large number of websites to gain a huge amount of free, non-upkeep items. (And it posts your code everywhere when you have a new one)
Sends ally invitations to a huge list of available codes from a large number of code sharing sites to build up your command.
Goes through internal game pages to scrape profiles for ally codes to send more invites to.
Quits automatically when you reach the 50 invite 24 hour limit or if your cookie expires.
Deposits money in the bank
Of course you can change the order or the functions, and they are all optional. All the code is here. The code is just bash, using grep, sed, awk, html2text, cat, etc. You will want to edit the variables to meet your needs before you use it of course. You can check out the code with svn:
svn co http://dev.xkyle.com/aftershock
Explaination of commands:
aftershock.sh – Main script, takes the argument 1-5 for the particular game you are playing. Needs the -i argument if you need the cookie from the ipod instead of firefox
go-ipod.sh – Runs each game consecutivly by vnc’ing to the ipod, running the game, getting the cookie, then running the appropriate aftershock.sh instance
spawnall.sh – Runs an exterm for each aftershock game. Useful if you have logged into each game through firefox, and need the robot to just do everything
I will try to support people who genuily who want to run this program. It is GPL. Email kyle@xkyle.com if you need help.
I’ve seen a lot of electronic fireflies on the internet. Here, here, and probably others. The theory is simple, just small LED’s charlieplexed with a microcontroller. I wanted to take it a step futher, with a light sensor, solar panel, and more complex firmware.
This is my first microcontroller project from scratch, and I got to learn all sorts of interesting things like SPI programming, Watchdog Timers, Sleep states, and many other things…
I wanted to flash more than just one firefly at a time, so I couldn’t do true PWM with all 12 with an ATtiny85. So I came up with my own way to control varying levels of brightness. Also I wanted a light sensor so the fireflies could come out slowly during the night, and the quickly disappear when the lights come on. The hardware was pretty difficult to solder, involving stripping magnet wire and hand soldering SMD LEDs.
Sorry for the poor pictures, my camera doesn’t do well in low light.
All the code is located here. You can check it out using svn or just download it directly. I was hoping to use a solar panel to make them self-sufficient, but they required too much power for them to be useful unless they were in direct sunlight.
The parts list and schematic and more info are on my wiki.
I’ve finally moved to Colorado, and I had to leave the big clock behind, and luckily I had finished it:
I finilized the code, installed the clock in my church, and programmed it for there needs. The code is stored here if someone want to see it. If you want to check it out run:
svn co http://dev.xkyle.com/clock
I have a little more technical info on my wiki, but it basically goes like this:
So using this and Openvpn, I can control the clock through the serial interface anywhere in the world, even Colorado! And of course the best part of it all, the church staff can also control it by sending an @reply using twitter!