16
\$\begingroup\$

I was wondering if it were possible to use multiple languages in the same submission. Not a polyglot, but using each of the languages. I have two thoughts on this.

  1. One language invokes the other. Let's say we have a Ruby + JavaScript solution. Then, you could have, say, puts %x(node a) in run.rb and console.log(x=>x) in a, and have rub.rb be the main solution.
  2. Alternatively, each language could read the output of the previous language as input. E.g., invoke like <input> | <language a> | <langauge b>.

How would these be scored? How would it be consistent, concerning the usage of langs (e.g. multiple usages of the same lang)? How would it compare with each of its component languages? Should it be allowed at all? If not, why not?


Here is an example of a multi-language submission, using method 2:

J + Ruby, idk bytes

Ruby, ruby.rb:

p gets.split.map(&:to_i).map{|s|s+4}

J, j.ijs:

exit echo 1+i.10

Invoke like:

j.ijs | ruby.rb

Output:

[5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
Dennis Mod
212k6 gold badges95 silver badges172 bronze badges
asked Sep 20, 2016 at 1:03
\$\endgroup\$
6
  • 8
    \$\begingroup\$ Seems dubious, but I can't come up with a concrete why of why this is bad. \$\endgroup\$ Commented Sep 20, 2016 at 1:16
  • \$\begingroup\$ Would this ever be useful? \$\endgroup\$ Commented Sep 20, 2016 at 2:08
  • 1
    \$\begingroup\$ @DJMcMayhem Maybe, maybe not. It might be fun. Is BF useful? :P \$\endgroup\$ Commented Sep 20, 2016 at 2:20
  • \$\begingroup\$ I feel like method 2 is a bit of a foul, the specialized invocation adds something not provided by either language. If method 1 is done from within a single file then maybe that's a feature? \$\endgroup\$ Commented Sep 20, 2016 at 2:54
  • \$\begingroup\$ This happens all the time with bash answers that also use sed, awk, dc, or bc, for example. \$\endgroup\$ Commented Sep 26, 2016 at 18:17
  • \$\begingroup\$ The dupe target specifically says it isn't concerned with scoring, so I'm reopening this. \$\endgroup\$ Commented Feb 27, 2017 at 15:42

1 Answer 1

14
\$\begingroup\$

Yes, it's perfectly valid

The byte count of the solution would be the sum of the byte counts of any files involved, plus the length of any special invocations needed.

For your first example, you have this:

//run.rb
puts %x(node a)
//a
console.log(x=>x)

This would be invoked as ruby run.rb, and would be in the language Ruby + nodeJS, with a byte count of 32, assuming no trailing newlines in the files.

For your second example, you could have something like this:

python -c 'print range(10)' | node -e 'console.log(x=>x*x)'

In this case, the byte count would be:

  • 15 bytes for the Python 2 program (print range(10))
  • 32 bytes for the non-standard invocation for a Python 2 program ( | node -e 'console.log(x=>x*x)')

or

  • 19 bytes for the nodeJS program (console.log(x=>x*x))
  • 30 bytes for the non-standard invocation for a nodeJS program (python -c 'print range(10)' | )

So, the byte count would be either 47 (counting Python 2 as the primary driver) or 49 (counting nodeJS as the primary driver). You would then choose the byte count more optimized for the scoring criteria (the 47 for , for example). The language for this submission would be Python 2 + nodeJS + sh (the sh is included because of the piping on the command line).

answered Sep 20, 2016 at 5:03
\$\endgroup\$
9
  • \$\begingroup\$ In the second scenario, one might want to golf it like python -c 'print range(10)'|node -e 'console.log(x=>x*x)'? \$\endgroup\$ Commented Sep 20, 2016 at 11:09
  • 1
    \$\begingroup\$ @ConorO'Brien Sure, but I'd rather have readable examples over fully-golfed examples. \$\endgroup\$ Commented Sep 20, 2016 at 11:12
  • \$\begingroup\$ Cool, just wondering. \$\endgroup\$ Commented Sep 20, 2016 at 11:13
  • 3
    \$\begingroup\$ Bash answers do this all the time, invoking stuff like awk or bc. Yet they are often called just "bash". \$\endgroup\$ Commented Sep 20, 2016 at 12:14
  • 2
    \$\begingroup\$ @Pietu1998 I think that's because usually all the code goes in the .sh file \$\endgroup\$ Commented Sep 20, 2016 at 16:34
  • \$\begingroup\$ @MartinEnder True. \$\endgroup\$ Commented Sep 20, 2016 at 16:38
  • \$\begingroup\$ @Pietu1998 they're often called bash + GNU Utils because that is more correct. I've also seen just bash called pure bash to make the distinction that it isn't using GNU utils. \$\endgroup\$ Commented Sep 21, 2016 at 11:51
  • 1
    \$\begingroup\$ Should most bash + GNU Utils answers be called GNU Util with a non-standard invocation then? This would save them at least the bytes for the name of one of the Utils. \$\endgroup\$ Commented Sep 23, 2016 at 18:40
  • 2
    \$\begingroup\$ I'm not sure why you'd count the program as either 47 or 49 bytes. python -c 'print range(10)' | node -e 'console.log(x=>x*x)' is 59 bytes long (less after stripping spaces), and that is the actual program. Shell scripts call different programs all the times, and they're never scored as commands to the first program plus pipe or something like that. \$\endgroup\$ Commented Dec 26, 2016 at 16:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.