Skip to content

Instantly share code, notes, and snippets.

@tomonacci
Created February 23, 2010 02:19
Show Gist options
  • Save tomonacci/311773 to your computer and use it in GitHub Desktop.
Save tomonacci/311773 to your computer and use it in GitHub Desktop.
Two methods that print out each other - it was kind of hard!
# Methods `a' and `b' will print out each other when called
def a;x="def a;x=";q=34;printf"def b;x=%cdef b;x=%c;q=34;"+(y="printf%c%s%%c%s%%c;q=34;%c(y=%c%s%c),q,q,q,x,x,q,q,y,q end"),q,q,q,x,x,q,q,y,q end
def b;x="def b;x=";q=34;printf"def a;x=%cdef a;x=%c;q=34;"+(y="printf%c%s%%c%s%%c;q=34;%c(y=%c%s%c),q,q,q,x,x,q,q,y,q end"),q,q,q,x,x,q,q,y,q end
# Slightly (8 bytes) shorter version
def a;x="def a;x=";printf"def b;x=%cdef b;x=%c;"+(y="printf%c%s%%c%s%%c;%c+y=%c%s%c),34,34,34,x,x,34,34,y,34 end"),34,34,34,x,x,34,34,y,34 end
def b;x="def b;x=";printf"def a;x=%cdef a;x=%c;"+(y="printf%c%s%%c%s%%c;%c+y=%c%s%c),34,34,34,x,x,34,34,y,34 end"),34,34,34,x,x,34,34,y,34 end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment