-1
Introduction
A known fact is that Jon Skeet can code Perl and make it look like Java. In this challenge you will try to do something similar.
Challenge
Write a piece of code of any length that can be executed without any errors/exceptions in two different languages. Your program can take inputs, give outputs, whatever it wants.
The code has to be executed with interpreters/compilers of your choice one after another (with basic settings, means you are not allowed to adjust the compiler/interpreter settings).
Note that the source code and any used sources (files, libs and so on) are not allowed to change during the execution of the script with the compilers/interpreters.
But which languages are "different"?
Two languages are different from each other if they are not the same language without looking at the version. Example: Python 3.5 is not different to Python 2.7.
Scoring
The final score consists out of several aspects:
charScore: Take your code and then (max charScore is 95)...
- Look at every function and delete all arguments (in echo "Hello" "Hello" counts as an argument). So now only keywords and functions count. Example: System.out.println(1+1); becomes System.out.println();
- Make all strings to empty strings and all regex and literals empty. Example: "khffshiufahk" becomes "" and all regex (without string) gets deleted.
- Delete all comments. Example: //Jon Skeet would also do this becomes [nothing] _Definition of "comment": _ Anything that doesn't change the execution of the program (So you could simply leave them out and nothing would change).
- Delete all characters that are not unicode 32-126. Example: print(2²) becomes print(2)
- Count only the occurrences of the letters. Example: hiiiiiii-thhheeeree has the same score as hi-there (means score of 8)
Here is a StackSnippet to do step 3 and 4 for you (report me if there is a bug):
function calcScore() { var onlyValidChars = ""; var code = document.getElementById("code").value; for (i = 0; i < code.length; i++) { if (code[i].charCodeAt(0)>=32 && code[i].charCodeAt(0)<=126) { //step 3 if (onlyValidChars.indexOf(code[i]) === -1) { //step 4 onlyValidChars += code[i]; } } } return onlyValidChars.length; } function showCalcScore() { alert("Your charScore: "+calcScore()); }
<body> <textarea placeholder="Insert your code here." id="code"></textarea> <br> <button type="button" onclick="showCalcScore();">calculate score</button> </body>
+20 if your code is still executable in both languages now (after the charScore-changes)
- +50 if running the code with the different interpreters does different things (eg order change, prints other things etc)
- +15 if your languages are Perl and Java
The answer with the highest score wins.
EDIT: I don't think that this is a duplicate (but very releated) because it has no "different language" limits and no score. On the other hand, I didn't know about so-called "polyglot"-code so maybe I am wrong.
This is my first question on this site. If anything is unclear feel free to ask or edit. (I'm not sure if everything is clear in this challenge.) – palsch – 2016-01-30T20:07:25.550
What tags should I use for this question? – palsch – 2016-01-30T20:07:46.823
@Mego It it very releated but not the same I think. – palsch – 2016-01-30T20:10:32.013
1The [tag:polyglot] tag applies, and I would also recommend looking over existing polyglot challenges if you haven't already done so. – PhiNotPi – 2016-01-30T20:13:17.720
The scoring is different. – palsch – 2016-01-30T20:17:52.187
You should make rule #1 under charScore include regex literals (and perhaps other kinds of literals). Otherwise a single regex literal that includes every single character is a valid Ruby+Perl submission. – Doorknob – 2016-01-30T20:19:42.020
@Doorknob You are probably right. That doesn't seem to work well. – palsch – 2016-01-30T20:21:42.023
How could I put that into regex? – palsch – 2016-01-30T20:23:00.877
Also, what is your definition of "comments"? – Doorknob – 2016-01-30T20:23:10.140
2Also, Pyth and Python 3 are very different. One is specifically designed for golfing, and the other isn't. Pyth was originally derived from python, but now is its own language. – Rɪᴋᴇʀ – 2016-01-30T20:24:34.343
@Doorknob Edited the question. – palsch – 2016-01-30T20:25:51.480
@RikerW Yeah, that was just an example. I know that the filtering is not the best. First, I wanted to have something like this but that would have made everything very complicated.
– palsch – 2016-01-30T20:28:17.387@Doorknob The question - charScore - 1 now includes regex and literals. But there is another problem: You could probably also make a request to http://abc.de/fegh... :(
– palsch – 2016-01-30T20:36:36.473@palsch just limit it to different versions of the same language. That generally works fine. – Rɪᴋᴇʀ – 2016-01-30T21:23:19.347