Hacker News new | past | comments | ask | show | jobs | submit login
Writing a triple polyglot script (nkanaev.github.io)
96 points by nkanaev on Feb 6, 2020 | hide | past | favorite | 19 comments



For something more ridiculous, feel free to check out this 281 language Polyglot: https://codegolf.stackexchange.com/questions/102370/add-a-la...


Direct link to the answer holding the 281 language one:

https://codegolf.stackexchange.com/a/198810/71130

Each language was added by a distinct answer, each answer building on the work of all the previous ones. The community teamwork in building such a monstrosity is beautiful.


These programs are absolutely insane and completely out of control. I feel like I read a chapter of the Necronomicon.

Thank you for posting this, it's brilliant! Now to look at a tree or something until I can identify which way is up again.


"On the 1rst Day of Perl-mas..."


There was a CTF challenge a couple years back that we had to make a Python/PHP/Node/Bash polyglot "quine". Here is my write up https://medium.com/@caioluders/polyglot-quine-rctf-2018-cats...


Ah, this reminds me of the time I encountered a polyglot "config file" in the wild in a university autograding system.

Instead of being parsed, it was `import`-ed and `include`-d in Python code and Makefiles. It had a `.py` extension so it took me a while to figure out why everything was breaking when I added some Python code in it. All in all, a very cursed setup.


There's some production code at my work that relies on a file being parsable in two languages


Languages with eval() kind of give you a pass on this challenge.

A more impressive alternative would be writing nested interpreters in multiple languages... Or writing code which runs in one "language" and then self modifies to another language which runs and subsequently self modifies, and so on.



There's a great history of polyglots. I saw this one published many years ago in a magazine: https://gist.github.com/erickedji/92398

    CuG #%*   POLYGLOT - a program in eight languages      15 February 1991  *+Ex=


I work hard to make sure that all of my Javascript is also valid Typescript.


If you love this, you're going to positively squee at Poc||GTFO, if you haven't read it yet:

https://www.alchemistowl.org/pocorgtfo/

I mean, does HN filter out PoC||GTFO release announcements or something? I seem to remember there being mention that it might've hit the filter list ..


Nope, that exact link has been posted 22 times on HN: https://hn.algolia.com/?q=https%3A%2F%2Fwww.alchemistowl.org...


Haha, nice tool, good fu.


I’m not sure if I should triple his salary, or just fire him for creating that monstrosity.

Haha, very cool though!


My favorite time I had to do this was for a real-life situation. I wanted a script that was both a bash script (for speed) and a ruby script (if you installed it the default way).

I came up with: https://github.com/sorbet/sorbet/blob/master/gems/sorbet/bin...


I actually had use for a polyglot script at work, since in .csproj files, <PreBuildEvent> is run as a "batch" cmd script on Windows, but with bash on Linux. The simplest trick I could find was this:

    rem () { ./bash-version.bash; exit $?; }
    rem skip rest of script if executed by bash
    rem batch script follows:
    IF %blah% EQU 0 etc.


This is one of the vanishingly small implementations of fizz buzz posted online that don’t have separate paths for fizzbuzz cases than for fizz and buzz cases.

Usual solve is %3 = fizz, %5 = buzz, %15 = fizzbuzz ...

If you change 3 or 5, you now have to go edit 15 too, does that not seem like a problem?

Nicely done.


Ahaha I love this. Very clever idea too, "Triple-hirable" possibly, but I feel your time is clearly better spent dreaming these nightmare concoctions!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: