12
1
Given the following Python 3 script:
def greet():
print("Hello, world!")
greet()
Prepend some lines to this text file so that it can be both executed as a Python program as well as compiled and run as a C++ program producing the same output Hello, world! (including the newline at the end):
$ python3 bilingual.py.cpp
Hello, world!
$ g++ bilingual.py.cpp && ./a.out
Hello, world!
The solution will be scored by the count of non-whitespace characters of the entire program, including the Python script:
sed 's/\s//g' bilingual.py.cpp|wc -c
5In the title you say add comments, however in the body you say you only have to prepend some lines. Which is it? – Post Rock Garf Hunter – 2016-11-05T17:18:18.080
@WheatWizard The title is a hint. If you can solve this by prepending arbitrary lines (non-comments) I will be puzzled. – Leon – 2016-11-05T17:37:18.177
This is a very nice question. My only remark would be to just stick to the byte count for scoring in the future. It's simpler to check for those on different systems. – Linus – 2016-11-05T21:40:05.913
@Linus I admit that selecting the score in a non standard way was a mistake. Will not repeat it in the future. – Leon – 2016-11-05T21:56:25.393
2Just a note: the provided sed command count the newlines, that are whitespace characters – edc65 – 2016-11-06T07:39:35.600