Skip to content

Instantly share code, notes, and snippets.

@panzi
Last active February 14, 2023 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panzi/031fac79e2fe7ca746c4c055b78ffdbf to your computer and use it in GitHub Desktop.
Save panzi/031fac79e2fe7ca746c4c055b78ffdbf to your computer and use it in GitHub Desktop.
The first file is a polyglot C and Python program that prints its own source code, i.e. a quine. This means you can run it as a Python script, but you can also compile it as a C program. The second file is the same, but in C and Ruby.
#include<stdio.h>
#define len int main(){char*
#define zip return 0;}
#if 0
def printf(f,*a):print(f%a,end=str())
#endif
len
s="#include<stdio.h>%c#define len int main(){char*%c#define zip return 0;}%c#if 0%cdef printf(f,*a):print(f%%a,end=str())%c#endif%clen%cs=%c%s%c;printf(s,10,10,10,10,10,10,10,34,s,34,10);zip%c";printf(s,10,10,10,10,10,10,10,34,s,34,10);zip
#include<stdio.h>
#define puts(c)void main(){c;putchar(10);}
#define dup char*
dup
s="#include<stdio.h>%c#define puts(c)void main(){c;putchar(10);}%c#define dup char*%cdup%cs=%c%s%c;puts(printf(s,10,10,10,10,34,s,34))";puts(printf(s,10,10,10,10,34,s,34))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment