"I know that language - that's Java. No? It's Perl?"

-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)...

    1. 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();
    2. Make all strings to empty strings and all regex and literals empty. Example: "khffshiufahk" becomes "" and all regex (without string) gets deleted.
    3. 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).
    4. Delete all characters that are not unicode 32-126. Example: print(2²) becomes print(2)
    5. 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.

palsch

Posted 2016-01-30T20:07:11.510

Reputation: 123

Question was closed 2016-01-30T21:01:48.710

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

Answers

1

PHP + Lenguage, 165

Scoring calculation: 95 + 20 + 50.

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

In PHP, this outputs the string verbatim (since there is no <? to signal for the preprocessor functionality).

In Lenguage, this is an infinite loop.

The charScore changes do not affect the program, as it consists of all 95 printable ASCII characters once, so it is eligible for the +20 bonus.

Doorknob

Posted 2016-01-30T20:07:11.510

Reputation: 68 138

Pig does not seem to fulfill the requirements of a valid programming language. – PhiNotPi – 2016-01-30T21:05:18.630

@PhiNotPi This has been rectified (s/Pig/Lenguage/). – Doorknob – 2016-01-30T21:24:06.737

I guess it's a lucky coincidence that lenguage program #95 is an infinite loop. – PhiNotPi – 2016-01-30T21:32:19.620

@PhiNotPi Not really. Anything that doesn't output that string would have worked anyway. – Doorknob – 2016-01-30T21:41:06.983