Ask HN: What's the most creative 'useless' program you've ever written?
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 ] threadThe only thing stopping me is that every time I over-engineer the hell out of it, then get annoyed and stop.
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
https://mathworld.wolfram.com/HaberdashersProblem.html
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
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
IOCCC gang rise up. This is mine: https://www.ioccc.org/years.html#2005_persano
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.
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
https://github.com/incanus/subleq
It was fun to see how simple a model of computation could actually be.
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
Yours looks like a nice improvement.
https://medium.com/build-ideas/newsletter
https://github.com/dylanaraps/pywal/tree/master/pywal/backen...
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.
Interestingly though, I've worked on similar algorithms before, some of which are in production.
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!
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)
https://medium.com/build-ideas/newsletter
Part 1 was fantastic.
[1] https://codegolf.stackexchange.com/questions/176966/golf-a-n...
Communicating via paste would work but speaking or typing was near impossible.
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.
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.
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 ))
Thank you for sharing.
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
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!)
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. :(
https://www.evalapply.org/posts/bad-matrix/
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.
This made me chuckle... it is how all great hacks begin.
> "This is not trivial, the 3270 does not want to do this"
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.
I hate when I'm having fun and accidentally make something useful :)
> 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.
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/.
I probably should have said in my original comment that the 3-D rotation itself was only 3 of the 15 lines:
The rest was ASCII art, animation, perspective projection, and geometry generation.https://github.com/Fethbita/BMP_to_Prime
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.
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).
Add some gravity and bitmapped obstacles (invisible of course to maximize the effect), and you had some real potential for nifty, if mesmerizing effects.