←back to thread

296 points reverseCh | 1 comments | | HN request time: 0.206s | source

I recently came across the concept of "useless" programs - pieces of code that serve no practical purpose but are fun, creative, or challenging to write. These could be anything from elaborate ASCII art generators to programs that solve imaginary problems. I'm curious to hear about the most interesting or creative "useless" programs the HN community has written. What was your motivation? What unexpected challenges did you face? Did you learn anything valuable from the experience? Some examples to get the ball rolling: 1. A program that prints the lyrics of "99 Bottles of Beer" in binary. A text-based game where you play as a semicolon trying to find its way to the end of a line of code. A script that translates English text into Shakespearean insults. Share your creations, no matter how quirky or impractical. Let's celebrate the joy of coding for coding's sake!
1. mindcrime ◴[] No.41926376[source]
Creative? I don't know about that, but here's something mildly interesting I did:

I came across the St. Petersburg Paradox[1] recently. The gist of this is that there's a coin-flipping game where if you go by the mathematical laws of probability, the expected payout is infinite. Meaning, you should play the game if offered the chance to play it for any finite amount of money. And yet most people will instinctively look at this and say "I wouldn't buy in to this game for more than $SOME_SMALL_AMOUNT".

To help myself understand the dichotomy, I wrote a simulation of the game in Java, and ran through 1 million rounds of playing the game, randomizing the coin flips, determining the payout, and then calculating the average.

What I found was that I wouldn't buy into this game for more than a few dollars. Because the infinite payout can only happen with infinite coin tosses as far as I can see, which would require infinite time, making that outcome irrelevant in the real world. And in a million game experiment, the average payout was usually around $20, with that outcome being highly affected by outlier outcomes. The usual outcome of individual trials was generally around $2 to $4 or so.

Useful for anything? No, but it was something fun to play around with.

[1]: http://en.wikipedia.org/wiki/St._Petersburg_paradox