Winning an Ugly Code Contest

↩︎ Mustafa Ozturk

2024 Dec 30

One year at my previous job, we held an ugly code contest. The goal was to write the ugliest piece of code possible, with certain restrictions, like file size constraints and ensuring it was executable.

I had once heard of quines—programs that reproduce their own source code. Inspired by this, I submitted the following code:

Screenshot of my submission

Along with the following explanation:

Upon running make uglycode

a C program will write and run a C++ program

the C++ program will write and run a Rust program

the Rust program will write and run a Python program

the Python program will write and run a Go program

the Go program will write and run a Nodejs program which will print “Hello Spiria!”

C > C++ > Rust > Python> Go > NodeJS > “Hello Spiria!”

I wanted to add more until I realized there was a file limit :D

Why the code is ugly:

  1. I had to remove all the whitespace and newlines possible so that everything fits 1024 bytes
  2. it took a lot of string escapes to make it work, for example you can’t have “““” in most languages
  3. its difficult to debug
  4. its unreadable

Compilers/languages/interpreters you will need:

gcc is used to compile the C program

g++ is used to the compile the C++ program

rustc is used to compile the Rust program

python3 is used to run the Python program

go is used to compile and run the Golang program

node is used to run the Nodejs program

to run: make uglycode

to cleanup the files the program will create: make clean

So, that’s how I won $100 and received a brief yet amusing email from my boss, who declared it the ugliest piece of code he had ever seen. 😆