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.
- One language invokes the other. Let's say we have a Ruby + JavaScript solution. Then, you could have, say,
puts %x(node a)inrun.rbandconsole.log(x=>x)ina, and haverub.rbbe the main solution. - 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]
-
8\$\begingroup\$ Seems dubious, but I can't come up with a concrete why of why this is bad. \$\endgroup\$Rohan Jhunjhunwala– Rohan Jhunjhunwala2016年09月20日 01:16:56 +00:00Commented Sep 20, 2016 at 1:16
-
\$\begingroup\$ Would this ever be useful? \$\endgroup\$DJMcMayhem– DJMcMayhem2016年09月20日 02:08:59 +00:00Commented Sep 20, 2016 at 2:08
-
1\$\begingroup\$ @DJMcMayhem Maybe, maybe not. It might be fun. Is BF useful? :P \$\endgroup\$Conor O'Brien– Conor O'Brien2016年09月20日 02:20:15 +00:00Commented 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\$Linus– Linus2016年09月20日 02:54:56 +00:00Commented 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\$Digital Trauma– Digital Trauma2016年09月26日 18:17:03 +00:00Commented Sep 26, 2016 at 18:17
-
\$\begingroup\$ The dupe target specifically says it isn't concerned with scoring, so I'm reopening this. \$\endgroup\$Dennis– Dennis Mod2017年02月27日 15:42:04 +00:00Commented Feb 27, 2017 at 15:42
1 Answer 1
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 code-golf, 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).
-
\$\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\$Conor O'Brien– Conor O'Brien2016年09月20日 11:09:35 +00:00Commented Sep 20, 2016 at 11:09 -
1\$\begingroup\$ @ConorO'Brien Sure, but I'd rather have readable examples over fully-golfed examples. \$\endgroup\$user45941– user459412016年09月20日 11:12:23 +00:00Commented Sep 20, 2016 at 11:12
-
\$\begingroup\$ Cool, just wondering. \$\endgroup\$Conor O'Brien– Conor O'Brien2016年09月20日 11:13:36 +00:00Commented 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\$PurkkaKoodari– PurkkaKoodari2016年09月20日 12:14:45 +00:00Commented Sep 20, 2016 at 12:14
-
2\$\begingroup\$ @Pietu1998 I think that's because usually all the code goes in the .sh file \$\endgroup\$2016年09月20日 16:34:44 +00:00Commented Sep 20, 2016 at 16:34
-
\$\begingroup\$ @MartinEnder True. \$\endgroup\$PurkkaKoodari– PurkkaKoodari2016年09月20日 16:38:44 +00:00Commented Sep 20, 2016 at 16:38
-
\$\begingroup\$ @Pietu1998 they're often called
bash + GNU Utilsbecause that is more correct. I've also seen just bash calledpure bashto make the distinction that it isn't using GNU utils. \$\endgroup\$Liam– Liam2016年09月21日 11:51:40 +00:00Commented Sep 21, 2016 at 11:51 -
1\$\begingroup\$ Should most
bash + GNU Utilsanswers be calledGNU Util with a non-standard invocationthen? This would save them at least the bytes for the name of one of the Utils. \$\endgroup\$Riley– Riley2016年09月23日 18:40:06 +00:00Commented 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\$2016年12月26日 16:56:50 +00:00Commented Dec 26, 2016 at 16:56
You must log in to answer this question.
Explore related questions
See similar questions with these tags.