Inspiration

I read the first Hitchhiker's Guide to the Galaxy book in high school. It was a lot of fun and I still remember laughing a lot in our group reading sessions. The geeky reference to the number 42 that comes from that book has been a personal favorite since then. Remembering the funny moments of the book and film has brightened many-a-day for me.

I have been wanting to figure out for myself why the answer to the ultimate question is 42. My theory was that the computer would have converted the question into the decimal representation of ASCII characters and then did some calculations on those decimals to arrive at the decimal solution. This is the silly algorithm I implemented for this hack.

What it does

The web application is supposed to be fun to look at, with the clunky computer illustration as a reference to the movie representation of the computer named Deep Thought. The UI is simple - it asks you for the question you want to ask Deep Thought (who is stranded in space like the hitchhikers). Asking the question will trigger the silly algorithm that will return a decimal number as the answer! Perhaps, this is what Deep Thought would have replied after millions of years of computation - except this app is much faster.

How I built it

I started out with trial and error to come up with a calculation on decimal representations of the ASCII characters of the question. I ended up transforming the ASCII table to exclude some characters (namely, space and the control characters) and then averaging out the decimal representation of the resulting string. Once I had an algorithm that actually returned 42 for the question, I started building the web page. I didn't need any backend for what I was trying to do, but I did want to have a single-page application, which is why I went with Angular (since I was a bit familiar with it). I designed a UI mockup using Canva (from the GitHub Student pack). After that, I spent all night working on the HTML/CSS for the UI. Then came the Angular parts, and finally deploying the static website to AWS S3.

Challenges I ran into

After building the UI and implementing the algorithm in TypeScript, I was able to experiment with providing some more inputs to the algorithm. Unfortunately, the algorithm ended up only returning values in the range 41 to 43 for all the English questions I asked of it. That's a bit disappointing because it makes it less believable. However, since we don't actually know what algorithm Deep Thought used to compute the answer and have no data on what answers to other questions would have been, it is still possible that Deep Thought "thought" like this.

I was trying to have my website exist on a nice domain name, but ran into issues with Route 53, which is what AWS suggests to use for registering domain names for static websites hosted on S3. Route 53 domain names aren't free and I couldn't find how to properly integrate S3 hosting with a custom domain name from somewhere else. I added a redirect rule from my domain name with Names.com to the S3 domain, but the Names.com domain doesn't show up in the url address bar when one is on the website.

Accomplishments that I'm proud of

Making a presentable web page. I have only made ugly websites up until now.

Actually coming up with an algorithm that computes 42 from the question. When I first had this idea, I wasn't sure if I would be able to do it. However, as I experimented with different algorithms, I found that it would be rather easy to come up with a gibberish one. Then, I did my best to come up with one that at least somewhat makes sense.

What I learned

I got more practice with Angular, HTML/CSS, and AWS. I learned about two AWS services - S3 and Elastic Beanstalk as I was considering how to host my app on AWS. I already had a bit of prior experience with AWS EC2 (the service I flocked to when I saw it was basically a personal remote VM machine), but I have now learned that there are quicker/easier ways to host websites on AWS.

What's next for hitch-hiker-42

It would be cool to implement another version of the algorithm using neural networks. I think training a neural network during the hackathon with such an obscure idea of a dataset would have taken too long, so that is why I didn't really consider that option. (I also wanted to try making an ASCII-based algorithm!)

Share this project:

Updates