Skip to content

Instantly share code, notes, and snippets.

@GlenDC
Created December 6, 2015 17:10
Show Gist options
  • Save GlenDC/11dadd47137b2c1a5587 to your computer and use it in GitHub Desktop.
Save GlenDC/11dadd47137b2c1a5587 to your computer and use it in GitHub Desktop.
A quine that switches between languages
PROGRAM QUINE
IMPLICIT NONE
WRITE(*, '(A)') '#!/usr/bin/python'
WRITE(*, '(A)') ''
WRITE(*, '(A)') 'sq = chr(39) ; dq = chr(34)'
WRITE(*, '(A)') 'ind = lambda str: '' '' + str'
WRITE(*, '(A)') 'sqe = lambda str: sq + str + sq'
WRITE(*, '(A)') 'dqe = lambda str: dq + str + dq'
WRITE(*, '(A)') ''
WRITE(*, '(A)') 'foc = ['
WRITE(*, '(A)') ' "PROGRAM QUINE",'
WRITE(*, '(A)') ' " IMPLICIT NONE",'
WRITE(*, '(A)') ' "",'
WRITE(*, '(A)') ' "END PROGRAM QUINE",'
WRITE(*, '(A)') ' "",'
WRITE(*, '(A)') ' ]'
WRITE(*, '(A)') ''
WRITE(*, '(A)') 'pyc = ['
WRITE(*, '(A)') ' "#!/usr/bin/python",'
WRITE(*, '(A)') ' "",'
WRITE(*, '(A)') ' "sq = chr(39) ; dq = chr(34)",'
WRITE(*, '(A)') ' "ind = lambda str: '' '' + str",'
WRITE(*, '(A)') ' "sqe = lambda str: sq + str + sq",'
WRITE(*, '(A)') ' "dqe = lambda str: dq + str + dq",'
WRITE(*, '(A)') ' "",'
WRITE(*, '(A)') ' "foc = [",'
WRITE(*, '(A)') ' " ]",'
WRITE(*, '(A)') ' "",'
WRITE(*, '(A)') ' "pyc = [",'
WRITE(*, '(A)') ' " ]",'
WRITE(*, '(A)') ' "",'
WRITE(*, '(A)') ' "pyc = (pyc[:8]",'
WRITE(*, '(A)') ' " + [ind(dqe(line) + '','') for line in foc]",'
WRITE(*, '(A)') ' " + pyc[8:11]",'
WRITE(*, '(A)') ' " + [ind(dqe(line) + '','') for line in pyc]",'
WRITE(*, '(A)') ' " + pyc[11:])",'
WRITE(*, '(A)') ' "",'
WRITE(*, '(A)') ' "for line in foc[:3]: print line",'
WRITE(*, '(A)') ' "for line in pyc:",'
WRITE(*, '(A)') ' " line = line.replace(sq, sq+sq)",'
WRITE(*, '(A)') ' " print ind(''WRITE(*, {}(A){}) {}''.format(sq, sq, sqe(line)))",'
WRITE(*, '(A)') ' "for line in foc[3:]: print line",'
WRITE(*, '(A)') ' ]'
WRITE(*, '(A)') ''
WRITE(*, '(A)') 'pyc = (pyc[:8]'
WRITE(*, '(A)') ' + [ind(dqe(line) + '','') for line in foc]'
WRITE(*, '(A)') ' + pyc[8:11]'
WRITE(*, '(A)') ' + [ind(dqe(line) + '','') for line in pyc]'
WRITE(*, '(A)') ' + pyc[11:])'
WRITE(*, '(A)') ''
WRITE(*, '(A)') 'for line in foc[:3]: print line'
WRITE(*, '(A)') 'for line in pyc:'
WRITE(*, '(A)') ' line = line.replace(sq, sq+sq)'
WRITE(*, '(A)') ' print ind(''WRITE(*, {}(A){}) {}''.format(sq, sq, sqe(line)))'
WRITE(*, '(A)') 'for line in foc[3:]: print line'
END PROGRAM QUINE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment