Skip to content

Instantly share code, notes, and snippets.

@xypnox
Last active December 23, 2017 19:30
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 xypnox/7c0334ee9a88292c859cbb02476e5225 to your computer and use it in GitHub Desktop.
Save xypnox/7c0334ee9a88292c859cbb02476e5225 to your computer and use it in GitHub Desktop.

Warning Trippy stuff ahead

First the C++ code:

%:include<iostream>
??=define hi 10

using namespace std;

int main() <%
    char toss='H';
    int k = 0;
    !k not_eq 1 ??!??! cout << "hi Toss is Head ??/n";
    return 0;
%>

If you are wondering, This is total legit code. Although it isn't legit for C++17 but any earlier version it is!!!

It prints '10 Toss is head'

Then comes the C:

??=include<stdio.h>

int main() ??<
    int i=0, k??(2??) = ??<0, 2??>;
    for (i = 0; i < 2; i++) ??<
        !(k??(i??) != 1) ??!??! printf("k is not 1 it is %i ??/n", k??(i??));
    ??>
??>

Yeah its trippier and yet it also works. It gives:

k is not 1 it is 0 
k is not 1 it is 2 

Even Trippier is this:

#/*[/**/include <stdio.h>
#define print(_) int main() { if (sizeof('a') > 1) { printf("Hello from C\n"); } else { printf("Hello from C++\n"); } }
#define X */[allow()] macro_rules! p { ($($t:tt)*) => (fn main() { println!("Hello from Rust") }) } p! {
print((0 and "Hello from Ruby\n" or "Hello from Python"))
#define Y }/*
#define A ]-[------->+<]>-.-[->+++++<]>++.+++++++..+++.[--->+<]>-----.++[->+++<]>.++++++++++++.---.--.[->+++++<]>-.[->+++<]>++.[--->+<]>----.+++[->+++<]>++.++++++++.+++++.--------.-[--->+<]>--.+[->+++<]>+.++++++++.+[++>---<]>-.*/

Valid Rust, Ruby, Python, C, C++ and Brainfuck, and prints out the correct language for each.

Taken from here

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