Showing posts with label 1 line code. Show all posts
Showing posts with label 1 line code. Show all posts

Thursday, March 25, 2010

A one line Python Quine

OK, Here's a one line Python program that prints its own source code:

s='s=%r;print s%%s';print s%s

This wikipedia article on Quines is a very good place to learn how these things work

Saturday, February 27, 2010

One line quicksort in Python

Here's a one line quicksort in python. I came up with this idea after looking at a 2 lines implementation in Haskel

qsort = lambda seq: [] if not seq else qsort(filter(lambda n: n<=seq[0], seq[1:]))+[seq[0]]+qsort(filter(lambda n: n>seq[0], seq[1:]))