Skip to content

Instantly share code, notes, and snippets.

@juliusgeo
Last active May 21, 2023 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliusgeo/832b5ede1760efa5f5969f6bf4fa2a46 to your computer and use it in GitHub Desktop.
Save juliusgeo/832b5ede1760efa5f5969f6bf4fa2a46 to your computer and use it in GitHub Desktop.
'Hello, World!' Simplified: Only 24 Lines of Python
h = [
    lambda a, b, c, d: 0,
    lambda a: 0,
    lambda a, b, c, d, e, f, g, h: 0,
    lambda a, b, c, d, e, f, g, h: 0,
    lambda a, b, c, d, e, f, g, h, i, j, k: 0,
    None,
    lambda a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, x, t: 0,
    lambda a, b, c, d, e, f, g, h, i, j, k, l: 0,
    lambda a, b, c, d, e, f, g, h, i, j, k, l, m, n, o: 0,
    lambda a, b, c, d, e, f, g, h, i: 0,lambda a: 0
]
b = 100
for i in h:
    if i is None:
        print(" ",end="")
        b-=1
        continue
    try:
        i()
    except Exception as exc:
        print(chr(int(str(exc).split(" ")[2])+b),end="")

This prints out "hello world" when ran. Explanation:

  • the string is first encoded using deltas, to keep the numbers small, which will help us later
  • each function is ran with no arguments, prompting Python to raise an error something like this: <lambda>() missing 4 required positional arguments...
  • take that error message, and the number in the middle is the value we're trying to get, add it to the initial value (100 for first word, 101 for second)
  • each lambda then needs to have the number of arguments corresponding to each letter's delta (luckily all these numbers are small, because we used deltas)

Why? Because I can. If you think this is cool (or fascinatingly horrible), then you should check out a competition I am running in the vein of the IOCCC for Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment