Skip to content

Instantly share code, notes, and snippets.

@tomonacci
tomonacci / co-quine.rb
Created February 23, 2010 02:19
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
@tomonacci
tomonacci / quine.rb
Created February 23, 2010 02:12
Quine in Ruby
printf x="printf x=%c%s%c,34,x,34",34,x,34