Ask HN: What's the most creative 'useless' program you've ever written?

296 points by reverseCh ↗ HN
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!

420 comments

[ 2.6 ms ] story [ 303 ms ] thread
(comment deleted)
A toy BASIC interpreter written in Guile Scheme.
(comment deleted)
About 10 or 11 years ago I wrote a bot that sat in our company Campfire chat training a Markov chain for each person. Then you could command it to imitate someone and it would spit out hilarious madlibs. This would likely not be amusing anymore, but back then it made people laugh.
This is so much fun. I did the same for a Discord server full of philosophy nerds, and the bot would say all sorts of things that started out profound-sounding and ended up absurd (one of our favorites: “I think therefore I am not italian”)
I did the same thing with a webchat I made for a bunch of my friends (back before discord was a thing)! Lots of fun.
I've done this as well, and I keep meaning to re-create it.

The only thing stopping me is that every time I over-engineer the hell out of it, then get annoyed and stop.

I learned in college Geometry class that you can transform a square to an equilateral triangle in 11 cuts or so

So I wrote a matlab program to draw the shapes, and cut them out, and it works

It’s mathematically exact, not just approximate

Still surprises me after 20 years, so I want to find this old program again lol

This got a downvote and I wonder if it’s from a person who doesn’t think it’s true
It more likely s from a person whose fingers are much larger than the distance between the up/downvote triangles on their device (that’s about everybody)
Indeed, although note that if you do fat-finger the up or down vote button, you can undo that by poking the 'unvote' or 'undown' link that appears on the same line.
Some men just want to watch the world burn.
The dissection of a square into an equilateral triangle (or vice versa) is sometimes known as the haberdasher's problem, and can be done in three straight-line cuts.

https://mathworld.wolfram.com/HaberdashersProblem.html

Hm interesting, I thought it was 11 pieces, not 11 cuts, but that one looks like 4 pieces, which is surprising

Now I am more curious to find this program

Either I didn't do it optimally, or there is some variation like a triangle/rectangle/square

I think there are some problems that have 3 shapes, or it could be triangle/pentagon or something

TIL that Gavin Theobald has produced several dissections from a triangle to a square on the surface of a sphere. Which would make pretty cool 3D-printed desk gizmos: make a ball with a triangular sector removed from one pole, a square sector removed from the other pole, and a set of wedge-shaped pieces that can be used to fill up either hole.

http://www.gavin-theobald.uk/HTML/Spherical/T90-S112.5.pdf

http://www.gavin-theobald.uk/HTML/Spherical/T100-S120.pdf

http://www.gavin-theobald.uk/HTML/Spherical/T120-S135.pdf

http://www.gavin-theobald.uk/HTML/Spherical.html

(comment deleted)
I wrote a program to launch and kill tight loop threads such that Windows Task Manager's performance graph would spell out text (though of course with spaces below lines in letters filled out).
A combinator reduction evaluator with a translator from lambda calculus to combinators. The creative part was getting a C compiler to parse combinator expressions with the traditional syntax, where function application does not have an operator and is left-associative, like S K K. http://www.ioccc.org/years.html#1998_fanf
Winning an IOCCC contest is far from being useless though:-)
Hey, I've seen some of your IOCCC entries. Even had some fun trying to understand them back in the day.

IOCCC gang rise up. This is mine: https://www.ioccc.org/years.html#2005_persano

Somehow, I have a rather small one: https://www.ioccc.org/2012/kang/kang.c

I think I have submitted once or twice before that got won, and all other entries were excessively long to be honest. Guess a conciseness is a virtue.

> Guess a conciseness is a virtue.

Indeed; quoting from my winning entry [1] that same year:

> This program celebrates the close connection between obfuscation and conciseness, by implementing the most concise language known, Binary Lambda Calculus (BLC).

> The submission implements the universal machine in the most concise manner conceivable.

[1] https://www.ioccc.org/2012/tromp/hint.html

Many years ago I wrote a text editor in brainfuck. It wrote out the file in memory as the user typed, and it'd shift its data structures successively farther in memory to avoid overwriting them as it went. A friend gave it one of the best compliments I've ever received and called it beautiful after watching it execute in a memory editor.
This is marginally useful, but I wrote a small ‘subleq’ playground — it’s an instruction set with just one instruction, “SUBtract and branch if Less-than or EQual to zero”.

https://github.com/incanus/subleq

It was fun to see how simple a model of computation could actually be.

Some people wrote a Forth interpreter on top of that.
Oh, this is totally also my jam. Will dig some of those up.
gopher://hoi.st has nice stuff for subleq and awk
A decade and a half ago, I came across this beautiful bar in Bahrain (online) that was visually appealing to the eye with contrasty colors. I was so fascinated by it that I started writing a simple algorithm to just extract out the dominant colors in the image, just for fun, but mostly because I was so lazy to open Photoshop and pick the colors out manually.

Turns out, this is actually a real challenging task for computers - what the eyes perceive as dominant, computers do not and vice-versa. For example, if you draw a small circle on a black board with white chalk, take a picture of it and ask a computer, it will tell you black is the dominant color because it covers most of the pixels. Whereas, any human would tell you the white drawing is the dominant color because it stands out.

There are some ways of guiding the computer to get the color palette you want out of an image, but they are never as accurate. Over the years, I would from time to time, throw a bunch of images at it - ranging from portraits to beautiful flowers from gardens to see how my algorithm would perform and improved it bit by bit. I would say, it is close to 90% accuracy now and I still work on it over the weekends. It has no use cases so far (for me). It just exists as a pure passion project that got me excited about programming such algorithms.

Recently, I did a Fashion degree just out of passion and I realized this code has so much applications for things like making mood boards and color palettes from inspiration boards. However, none of my professors nor fellow students were impressed or saw utility in it because they believed no algorithm can match or replace a true creative process. They are pretty old-school about this, so, there's that. But, they just didn't seem to understand the technical challenge about this seemingly simple task.

However, over the years, I did build an API around this algorithm, kept fine tuning it and even made some marketing material for it. For no purpose other than reminding myself of why I am excited about programming.

If you're interested, here is a decade old snapshot of the algorithm's output:

https://ibb.co/SvYLLG3

https://ibb.co/tHKf9T8

Hey this is pretty cool! Have you thought about putting it online? I've occasionally used tools like Adobe's color scheme finder, where you upload an image and it suggests a fitting colorscheme derived from the photo. Though honestly theirs doesn't perform too well.

Yours looks like a nice improvement.

It's a cool problem. Did you ever see the pywal project? It has a few backends for generating palettes, I think the best is the imagemagick one in wal.py

https://github.com/dylanaraps/pywal/tree/master/pywal/backen...

Also, I guess dylanaraps has archived all his projects and taken up farming? Fair enough

> Also, I guess dylanaraps has archived all his projects and taken up farming? Fair enough

Seems the author mostly wrote Bash (and Python) code. Makes sense that at one point they just had enough.

Thanks, that looks useful. Will check it out :)
I'm replying because it's the first mention of Bahrain I've come across on HN. I spent the first 30 years of my life there.

Interestingly though, I've worked on similar algorithms before, some of which are in production.

I’m hear about that country at work often, mostly people traveling back talking about all the crazy expensive cars they saw.
That would depend largely on where you're comparing it to I guess.

One reason is that fuel is extremely cheap - I thinks it's only cheaper in Saudi Arabia and Kuwait. When fuel cost is almost not a factor then it basically becomes about which fancy car is affordable.

There's a huge wealth gap out there as well, and quite a tiny population. I would highly recommend checking it out some day. It's quite an interesting little island!

I’ve heard enough about the place that I’m not interested!
Thanks, I've been meaning to check out that Buddha bar I used in the picture. I have a sentimental attachment to it, being my first entry into such programming and all. I even thought about laying low in Bahrain, seems like a really cool place.
Fantastic stuff, this would be very useful in print art work I do.

For those further interested you see the issue this resolves by converting an full color image to an indexed image (often key colors, but low in total pixel count are neglected)

Short URL generator with emoji as characters.

Communicating via paste would work but speaking or typing was near impossible.

My Library of Ordinal Notation Systems shows a way you can systematically write more and more complex code, with no end---even if you had access to strong AGIs, they could never "finish" the exercise. https://github.com/semitrivial/IONs
I like inserting art, like the header to https://simonsarris.com

A village pops up. There is no point to it. You can click to make more houses. You can right-click to drag things around. When I touch it again I think I'll add a sun and moon that track the time of day for wherever the user is located. Actually the footer has art too, each page has a semi-randomly assigned illustration from public-domain (old) art that I've found. Like drawings from James McNeill Whistler, for instance. I use his illustrations in 'useful' websites too.

Actually, I experimented with the sun/moon a few years ago, in this version: https://simonsarris.github.io/simeville/

If you left-click drag the sun downwards, you'll see the moon come up. That one is open source, but the code is quite slapdash compared to the new one. Also you have to click ITS TIME TO BUILD to get the buildings.

In general I think websites could be a lot more pretty (gorgeous even), silly, interesting, and a lot less corporate chic than they currently are.

I like having this kind of animation on my homepage, too.

Currently I just have an animated GIF background, but I've had some animated ASCII art in the past.

I'm currently working on animating a fractal drawn with HTML Canvas.

Your houses and pencil style are very cute, I feel inspired to make something similar.

I'd like if clicking in the same place would grow whatever's there.

For graphics, check out KM Alexander
Im totally using some of these on my next personal site redesign! The charm is fantastic and cozy <3
I really went down the rabbit hole reading the history of the map brushes, thanks for sharing!
I have to agree, I really miss the 90's when websites had more of a fun artistic creative and personality feel than templated. I see the use for both, but I miss it :)
If the moon is rising when the sun sets, it will be a full moon. But your graphic shows a partial phase :)
On Earth, with a single Sun.

But apparently this planet has some very strong radiation protection, possibly synthetic, that blocks out the strong ultraviolet light from their second Sun. That ultraviolet is reflected back in the visible spectrum from the surface of their moon though - thus giving the appearance of a crescent during the entire cycle. The "dark side" is still lit, just lit less.

That was fun ))

Beautiful personal site!
Your webpage is gorgeous, congrats!
Your website is very cute. I live on a certain floor of a building, and although the content of the site has no meaning to me, I kept looking at it for a long time, as if I were reading a novel.

Thank you for sharing.

I like this a lot. Beautiful, creative, really quite charming.
I love the page. I find it very inspiring :)
I like it, and I agree with you. Websites follow some simple design rules, some from typesetting, some new especially for the Web. Not least because of the behaviour of base components and the availability of styling libraries that keep their own smell around no matter what one does.

I like to draw on my websites too. I write a gpu-rendered background for basically any website I make for fun.

https://gtblank.org

https://ungut.at

Wow awesome! Reminded me of Cucinelli's AI website: https://www.brunellocucinelli.ai/ which is one of the best one I've seen. It's dedicated to Mr Cucinelli's life and beliefs. The aesthetics are similar.
Cute! I wonder how hard it would be, rather than having the houses "bounce" up, to make some kind of CSS animation that would look a bit like they were being sketched, some kind of gradual reveal..
For me it is for instance my involvement in the demo-scene in the 90’s.

A concrete example is Nikki, a demo released in 96 and captured (with some technical difficulties) by a friend here https://youtu.be/t8o-uuq73UU?si=4dlTla0s2mDCVzCK

Working on anything “useless” is profoundly life changing and “useful” on the long run!

Only now am I able to do more similar stuff (my current research is around music + code + lightning and videos, this time connected to real life performances), and it is massively pleasurable (and also likely one of the most technical types of work I will be working on for now!)

Yeah the demoscene jumps out as a good candidate to represent "creative 'useless' programs". :)

I make a few demos, but my personal favourite was this 4k (windows executable less than 4096 bytes):

https://www.youtube.com/watch?v=sBcwQCBpEiE

It uses all the fancy compressing linker tech (called crinkler) along with a tiny music player and a glsl raymarcher.

I tried to download it but all I get is virus warnings now... I guess malware devs also like crinkler. :(

"The Matrix" raining characters, but really bad, and in Bash (:

https://www.evalapply.org/posts/bad-matrix/

Oh man that brought back a memory.

I once had a job operating an ibm mainframe. it was the night shift of a low tier job mainly feeding tapes to the machine. I would spend the downtime reading the documentation for what was for me a foreign system. The mainframe.

This system was set up as vse(a batch processing operating system) over z/os, however the operators would login to cms(a more interactive operating system) on 3270 terminals.

If unfamiliar with 3270 terminals they are very different than the VT style terminals we tend to use. the main difference is VT terminals are in a sort of immediate mode(they print to the screen and read from the keyboard asynchronously) 3270 terminals are more like a html form, you fill out the form and send the whole thing to OS.

My great useless task was to build a matrix rain screensaver on the 3270, This is not trivial, the 3270 does not want to do this, I had to figure out how to spoof an immediate mode, I got it half working, I could print to the screen async like but I could never figure out how to read from the keyboard without blocking.

Once I had my async tty library, my next great useless task was to make an analog clock screen saver. This was it's own pile of worms as rexx(the cms scripting language) had no trig functions. I was smuggling in printouts from the nist library of functions on how to calculate sin, tan, pow... etc... and ended up writing some of the worlds slowest trig and exponential libs.

I think the nist library was this https://dlmf.nist.gov/ I have a great, perhaps unwarranted respect for nist to this day for providing this amazing resource.

Unfortunately I was not able to save any of my code from that job, I would love to look at it again.

Wow that's a great story; thanks for sharing! If you have a blog, please copy-pasta this there. It needs to live!

This made me chuckle... it is how all great hacks begin.

> "This is not trivial, the 3270 does not want to do this"

Given that this site is called "Hacker News", it's worth mentioning that '"useless" programs - pieces of code that serve no practical purpose but are fun, creative, or challenging to write' is one of the central definitions of ”hack”.

I've written some: a programming language interpreter based on Abadi and Cardelli's untyped ς-calculus; a two-kilobyte web server in assembly (which accidentally did turn out to be useful); a self-compiling compiler from a sort of Forth dialect to i386 ELF executables; a translator from standard English orthography to an ASCII alphanumeric phonetic orthography I designed; a one-kilobyte programming language interpreter with dynamic multimethod dispatch and pattern-matching; a base-3 calendar based on the Sierpinski triangle; a C interpreter in Python I used for bytebeat livecoding; several implementations of Tetris, one of which is a 2K ARM executable; an operating system for ARM consisting of five instructions; a few raytracers; a Space Invaders game; a minimal roguelike in Forth; a library for manipulating Boolean functions as Zhegalkin polynomials; many symbolic differentiators; a sort of polyrhythmic drum machine called Pygmusic; a parametric CAD system in PostScript for laser-cutting MDF; 3-D rotating objects in ASCII art in 20 lines of Python; Karplus-Strong string synthesis in one line of C; an audio PLL in one line of C; an RPN calculator with forward-mode automatic differentiation; a slide rule in Tcl/Tk; a port of the logic-programming EDSL μKanren to OCaml; several fractal renderers; a decoder for the "gridfonts" Hofstadter and his research group designed; a Hershey font decoder; several maze generators; a generator for balanced-nonary multiplication tables; a vocoder; a Doom-like first-person raycaster; a teapot mod for the Minetest game; a compiler for a subset of Scheme written in itself; etc.

A lot of this is in http://canonical.org/~kragen/sw/dev3/ which you can clone with Git. I'd be happy to elaborate on any of these if you are interested.

> which accidentally did turn out to be useful

I hate when I'm having fun and accidentally make something useful :)

It was more that I thought the approach I was taking would doom it to being uselessly slow, but it turns out Linux is actually pretty fast at forking, especially when your process's entire memory map is 20K :-)
> a Space Invaders game

> a minimal roguelike in Forth

> 3-D rotating objects in ASCII art in 20 lines of Python

> an RPN calculator with forward-mode automatic differentiation

Those all sound pretty cool. Are those in the link you provided? I'd be interested in seeing how you did the 3-D rotations in only 20 lines, or what a minimal roguelike in Forth would look like.

Thanks! Two of them are there! Or, sort of, three of them.

The Space Invaders game is http://canonical.org/~kragen/sw/dev3/qvaders.html, built on the game engine in http://canonical.org/~kragen/sw/dev3/qj2d.js. An earlier version without the engine, the explosions, or the Xbox support is at http://canonical.org/~kragen/sw/dev3/invaders.html.

The minimal roguelike is http://canonical.org/~kragen/sw/dev3/wmaze.fs. It runs in a few different Forths (GForth is probably the easiest) but I haven't ported it to F83 yet. There's an asciicast at https://asciinema.org/a/672405. I'm kind of a novice at Forth, so I might not be doing things in the best way.

The ASCII-art rotating cube is http://canonical.org/~kragen/sw/netbook-misc-devel/rotcube.p.... It's actually only 15 lines of Python. A longer wireframe Unicode braille version is at http://canonical.org/~kragen/sw/dev3/braillecube.py with an asciicast at https://asciinema.org/a/390271. There's also a 41-line C++ ASCII-art version at http://canonical.org/~kragen/sw/dev3/rotcube.cpp and a 42-line semi-wireframe C version using my graphics library Yeso at https://gitlab.com/kragen/bubbleos/-/blob/master/yeso/cube.c.

The RPN calculator is at http://canonical.org/~kragen/sw/81hacks/autodiffgraph/.

Thanks! I upvoted you but forgot to reply. Those are as interesting as I thought they'd be.
Awesome, I'm glad you liked them!

I probably should have said in my original comment that the 3-D rotation itself was only 3 of the 15 lines:

  s = 0.1                                 # sine
  c = (1 - s**2)**0.5                     # cosine
  ...
  cube = [(c*x + s*z, y, -s*x + c*z) for x, y, z in cube] # Rotate by theta.
The rest was ASCII art, animation, perspective projection, and geometry generation.
I have written a lua interpreter in JASS (the language used for WarCraft 3 maps). It's useless because at that point WC3 gained native lua support.
Solving the Dining Philosophers problem using systemd

It gave me the chance to play with some old unix concepts in an nspawn container.

https://github.com/brightbox/systemd-dining

As well as incorporating the Philosopher’s Song and some profound statements into the journal.

Twofer

I wrote a flame simulation in x86 assembly language. Total hoot.

I also wrote an Easter egg that shipped in a major software company’s software and is immortally burned onto thousands of DVDs slowly rotting in landfills. This one was fun and challenging because I had to mask the names of the product team from easy detection, I had to convert string text to my own custom 8x3 pixel font for rendering, I played with palette animation to create some fun raining effects, and I packed it into just a few Kb of the DOS end of a Windows executable (back in the day, 16-bit Windows apps could be linked with a custom DOS loader in case you tried to run the Windows app from the cmd line).

What kind of trigger did it have? some kind of key sequence or certain day of the year?
You passed a phrase on the command line. Honestly I made it all too hard to find, but Easter eggs were a bit dangerous for one’s career :)
I loved doing some particle simulations in C++, good old mode 0x13 style. Create a gradient palette, apply simple averaging of pixels values on each frame, draw each particle with additive translucency, and you ended up with a pretty cool water-like effect.

Add some gravity and bitmapped obstacles (invisible of course to maximize the effect), and you had some real potential for nifty, if mesmerizing effects.