Skip to content

Instantly share code, notes, and snippets.

@gnidan
Created September 20, 2013 03:54
Show Gist options
  • Save gnidan/6633103 to your computer and use it in GitHub Desktop.
Save gnidan/6633103 to your computer and use it in GitHub Desktop.
coffeescript quine
escape = (str) ->
return '' if str is ''
first = str[0]
rest = str[1..-1]
first = if first is "'" or first is "\\"
"\\#{first}"
else
first
return first + escape(rest)
str = [
'escape = (str) ->',
' return \'\' if str is \'\'',
' first = str[0]',
' rest = str[1..-1]',
' first = if first is "\'" or first is "\\\\"',
' "\\\\#{first}"',
' else',
' first',
' return first + escape(rest)',
'str = [',
']',
'for l in [0..9]',
' console.log str[l]',
'for l in str',
' console.log " \'#{escape(l)}\',"',
'for l in [10..16]',
' console.log str[l]',
]
for l in [0..9]
console.log str[l]
for l in str
console.log " '#{escape(l)}',"
for l in [10..16]
console.log str[l]
@gnidan
Copy link
Author

gnidan commented Sep 20, 2013

(snark) gnidan: ~/tmp $ coffee quine.coffee | diff quine.coffee - | wc -l
       0

woot!

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