Swapping languages on CodinGame (a.k.a. system() calls)


Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Swapping languages in CodinGame

... a.k.a. 'how to use system() calls?'

This Tech.io playground explores how to use a coding language within another language in the context of CodinGame puzzles. Topics we will cover:

  • Calling an interpreter from bash
  • Calling an interpreter from other languages
  • Calling a compiler from bash
  • Checking the compiler / runtime versions

Motivation and usage

CodinGame is about improving coding skills by solving puzzles (and by participating in contests). This playground is really just a sidetrack, a kind of 'hacking passtime'. Some ideas might come in handy, although using system() calls is rarely a best practice in real projects.

It is not meant to encourage you to circumvent the CG language selector and to submit a solution in another language than you labeled it.

I personally don't like the usage of system() calls at all, especially in codegolf, where it made the per language leaderboards rather pointless. I still have some (<10) older non-bash solo puzzle submissions in bash, but I try to replace them with a proper script as I improve my (rather basic) skills in bash.

Sample puzzle

In many examples I will use my solutions in different languages for a CG community solo puzzle called Rubik. This is one of the simplest and shortest puzzle on CG. It is more an elementary school math question than a coding puzzle. Still, if you don't like spoilers, go and solve it on your own before going to the next page on this playground.

Contributions welcome

As you will see, this playground is far from complete. For some languages I couldn't figure out the proper syntax yet for the system() call or how to invoke the compiler within the CG runtime. If you have suggestions for improvements, please:

  • send me (TBali) a private message on CodinGame;
  • or give a pull request directly to the github repo of this playground;
  • or just leave a comment here on Tech.io.

Regarding attributions: some of the ideas here I found in a bunch CG forum posts or chat messages. Many command line arguments are taken from a published code by Westicles (a.k.a. Mrs.GloriaZindlebocker).

Let's get started!

How to call an interpreter from bash with a one-liner code?

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content