Add comments to a Python script and make it a bilingual Python/C++ “program”
Score 119
(Thx @Linus for the byte count)
(1 byte saved thx @Conor O'Brien) (1 byte saved thx @PieCot)
Counting bytes again by hand, I found 113. Maybe it's right this time. No it's not
#include <cstdio>
#define def main(){0?
#define print(x) puts(x);}
#define greet()
Notes: stdio and puts are still alive and kicking in C++. The missing int type is valid in C++ 4. Test
Score 116
Prepend:
#include<cstdio>
#define print(A)main(){puts(A);}
#define greet()
#define \
The preprocessor backslash \
pulls the nasty :
containing line into an unused macro. Try it here.
Thanks to edc65's answer for the note about implicit int in C++4.
Thanks to PieCot's answer for suggesting <cstdio>
over <stdio.h>
.
Thanks to Leon for suggest I remove the X
in the original #define X\
.
Score 131 130 134
The lines to be prepended are:
#import <iostream>
#define def int main(){0?
#define greet()
#define print(A) 0;std::cout<<A"\n";}
And the resulting code:
#import <iostream>
#define def int main(){0?
#define greet()
#define print(A) 0;std::cout<<A"\n";}
def greet():
print("Hello, world!")
greet()
Testing
C:\Users\Conor O'Brien\Documents\Programming\golf
λ type bilingual.py.cpp
#import <iostream>
#define def int main(){0?
#define greet()
#define print(A) 0;std::cout<<A"\n";}
def greet():
print("Hello, world!")
greet()
C:\Users\Conor O'Brien\Documents\Programming\golf
λ sed 's/\s//g' bilingual.py.cpp|wc -c
134
C:\Users\Conor O'Brien\Documents\Programming\golf
λ g++ bilingual.py.cpp 2>nul && a
Hello, world!
C:\Users\Conor O'Brien\Documents\Programming\golf
λ python bilingual.py.cpp
Hello, world!
C:\Users\Conor O'Brien\Documents\Programming\golf
λ