5 added 1203 characters in body
source | link

Python 3 and JavaScript, 145134 bytes

WorkHere's my (final?) attempt:

a='eval(a.split(" ")[2%-4]),1//2# q=String.fromCharCode(39);console.log("a="+q+a+q+a.slice(-8)) print(a[-12:]%a) a=%r;eval(a)';eval(a)

It can probably be golfed a bit more, especially if anyone knows a better way to get single quotes in progessJavaScript.


Boiled down, the program looks like this:

a='a long string';eval(a)

The eval() function will evaluate expressions in both languages. So the long string gets executed:

eval(a.split(" ")[2%-4]),1//2# ... the rest gets commented out

This splits the long string by spaces and evaluates the substring indexed by 2%-4. JavaScript will run the third substring (2 % -4 == 2) and Python the second last (2 % -4 == -2), because their modulo operators behave differently for negatives.

The rest of the string gets ignored in both languages. JavaScript stops at the //, while Python sees it as integer division and stops at the #.

So JavaScript prints the source code to the console here:

q=String.fromCharCode(39);console.log("a="+q+a+q+a.slice(-8))

And Python here:

print(a[-12:]%a)

Both make use of the final part of the string, which is a template of the program:

a='print(a[78:]%a) q=String.fromCharCode(39);console.log("a="+q+a+q+a.slice(82)) a=%r;eval(a.split(" ")[0|0=="0"])';eval(a.split(" ")[0|0=="0"])

Python 3 and JavaScript, 145 bytes

Work in progess.

a='print(a[78:]%a) q=String.fromCharCode(39);console.log("a="+q+a+q+a.slice(82)) a=%r;eval(a.split(" ")[0|0=="0"])';eval(a.split(" ")[0|0=="0"])

Python 3 and JavaScript, 134 bytes

Here's my (final?) attempt:

a='eval(a.split(" ")[2%-4]),1//2# q=String.fromCharCode(39);console.log("a="+q+a+q+a.slice(-8)) print(a[-12:]%a) a=%r;eval(a)';eval(a)

It can probably be golfed a bit more, especially if anyone knows a better way to get single quotes in JavaScript.


Boiled down, the program looks like this:

a='a long string';eval(a)

The eval() function will evaluate expressions in both languages. So the long string gets executed:

eval(a.split(" ")[2%-4]),1//2# ... the rest gets commented out

This splits the long string by spaces and evaluates the substring indexed by 2%-4. JavaScript will run the third substring (2 % -4 == 2) and Python the second last (2 % -4 == -2), because their modulo operators behave differently for negatives.

The rest of the string gets ignored in both languages. JavaScript stops at the //, while Python sees it as integer division and stops at the #.

So JavaScript prints the source code to the console here:

q=String.fromCharCode(39);console.log("a="+q+a+q+a.slice(-8))

And Python here:

print(a[-12:]%a)

Both make use of the final part of the string, which is a template of the program:

a=%r;eval(a)
4 deleted 19 characters in body
source | link

Python 3 and JavaScript, 163145 bytes

Work in progess.

p='print(a%a='print(p,a)a[78:]%a) q=String.fromCharCode(39);console.log("p="+q+p+q+";a="+q+a+q+a"a="+q+a+q+a.slice(982))';a='p=%r;a=%r;eval a=%r;eval(pa.split(" ")[0|0=="0"])';eval(pa.split(" ")[0|0=="0"])

Python 3 and JavaScript, 163 bytes

Work in progess.

p='print(a%(p,a)) q=String.fromCharCode(39);console.log("p="+q+p+q+";a="+q+a+q+a.slice(9))';a='p=%r;a=%r;eval(p.split(" ")[0|0=="0"])';eval(p.split(" ")[0|0=="0"])

Python 3 and JavaScript, 145 bytes

Work in progess.

a='print(a[78:]%a) q=String.fromCharCode(39);console.log("a="+q+a+q+a.slice(82)) a=%r;eval(a.split(" ")[0|0=="0"])';eval(a.split(" ")[0|0=="0"])
3 deleted 12 characters in body
source | link

Python 3 and JavaScript, 175163 bytes

Work in progess.

p='print(a%(p,a)) q=String.fromCharCode(39);console.log(a.replace(/%+r/,q+p+q)"p="+q+p+q+";a="+q+a+q+a.replaceslice(/%+r/,q+a+q9))';a='p=%r;a=%r;eval(p.split(" ")[+(0=="0")][0|0=="0"])';eval(p.split(" ")[+(0=="0")][0|0=="0"])

Python 3 and JavaScript, 175 bytes

Work in progess.

p='print(a%(p,a)) q=String.fromCharCode(39);console.log(a.replace(/%+r/,q+p+q).replace(/%+r/,q+a+q))';a='p=%r;a=%r;eval(p.split(" ")[+(0=="0")])';eval(p.split(" ")[+(0=="0")])

Python 3 and JavaScript, 163 bytes

Work in progess.

p='print(a%(p,a)) q=String.fromCharCode(39);console.log("p="+q+p+q+";a="+q+a+q+a.slice(9))';a='p=%r;a=%r;eval(p.split(" ")[0|0=="0"])';eval(p.split(" ")[0|0=="0"])
2 deleted 6 characters in body
source | link
1
source | link