19
\$\begingroup\$

Task

Write some code that can be rearranged into n different programs in n different languages each outputting a distinct number from 1 to n.

No two languages should be the same however different versions of "the same language" will be considered distinct languages, as long as they have different major version numbers. For this challenge REPL environments are not distinct from their parent languages but are still a language. Each language should run on a distinct permutation of the source code and output a distinct number in the range.

Permutations will be counted in bytes not in characters.

You should include each permutation that is run with the language that it is run in for testing purposes.

Scoring

Your score will be the

Scoring equation

Where N is the number of languages and L is the number of unique orderings of the programs bytes.

L is not equal to the length of the program

(unless the program is 1 or 0 bytes)

Here is a python script to calculate L courtesy of Conor O'Brien.

L is equal to the length of the program factorial if and only if there are no repeated bytes in the program.

The goal is to maximize your score.

\$\endgroup\$
  • \$\begingroup\$ Related. \$\endgroup\$ – Martin Ender May 9 '17 at 19:00
  • \$\begingroup\$ are comments allowed? \$\endgroup\$ – Adám May 9 '17 at 19:05
  • \$\begingroup\$ @Adám There would be no reasonable way to ban comments \$\endgroup\$ – Sriotchilism O'Zaic May 9 '17 at 19:06
  • \$\begingroup\$ So if # is the comment symbol in 5 languages, good solution would be 1#2345 \$\endgroup\$ – Adám May 9 '17 at 19:06
  • \$\begingroup\$ @Adám that gives you a score of 1/6. I'm sure a score of 1 is easily possible with a 2-byte program (or a 1-byte program for that matter). And adding more digits reduces your score. \$\endgroup\$ – Martin Ender May 9 '17 at 19:08
30
\$\begingroup\$

34 Languages, 19 bytes, Score: 38,832,018,459,912,437,760,000

Here is a quick answer I threw together to show that it is possible to get an answer scoring better than 1.

 12233echo*+--@#..;

1. NTFJ

#*22331+..@o;-- ech

This outputs via character code, which is allowed by meta consensus.

Try it here

2. Tcsh

echo 2;#..1@2+33*--

3. 05AB1E

2231*+..@echo ;--#3

Try it online!

4. Actually

@..o; eho1#c3223-*+-

Try it online!

5. Befunge 98

23+.@.21*#3o;-- ech

Try it online!

6. Cubix

123+23*o@#;-- ech..

Outputs by character code

Try it here

Unfolded code:

    1 2
    3 +
2 3 * o @ # ; -
- e c h . . . .
    . .
    . .

7. Haskell 8 REPL

3+2*2 --31#;@..echo

8. Seriously

@..o; eho1#c3223-+*-

Try it online!

9. ><>

33*o;2+..@#12-- ech

Outputs by character code

Try it online!

10. Befunge

33*1+.@.#22o;-- ech

Try it online!

11. brainbool

323*+..@echo ;--#12

Try it online!

12. 2sable

233*+..@echo ;--#12

Try it online!

13. Hexagony

13;2#2+@*3o-- ech..

Outputs by character code

Try it online!

Unfolded code:

  1 3 ;
 2 # 2 +
@ * 3 o -
 - e c h
  . . .

14. R

12+2#*33..@o; ech

Try it online!

15. bc

12+3#*23..@o;-- ech

16. Python 3 REPL

13+3#*22..@o;-- ech

17. irb (Ruby 2.4 REPL)

13+2*2#3..@o;-- ech

18. PowerShell

12+2*3#3..@o;-- ech

19. Python 2 REPL

13+2*3#2..@o;-- ech

20. Python 1.6.1 REPL

23-3#-+*21..@o; ech

21. Ksh

echo 21;#..2@3+3*--

22. Bash

echo 22;#..1@3+3*--

23. Zsh

echo 23;#..1@2+3*--

24. Applescript

23+1 --#2*3..@o;ech

25. Lua REPL

23+2 --#1*3..@o;ech

26. Julia REPL

23+3 #2*1..@o;--ech

27. irb (Ruby 1.9.3 REPL)

13*2+3-2 #..@o;-ech

28. Haskell 7 REPL

13*2+2--3#;@.. echo

29. J

echo --1#.23;@+2*.3

Try it online!

30. Nim

echo 33-2-1;#..@2+2*

31. fish

echo 31;#3-2-..@2+2*

32. PHP

echo 32;#+123*@..--

<?php is not needed due to this meta

Try it online!

33. Golfscript

3.#.1223*@+o;-- ech

Try it online!

34. Octave

33+1 #22echo*--@..;

Try it online!

\$\endgroup\$
  • 5
    \$\begingroup\$ And that's why I hate REPL-capable languages \$\endgroup\$ – Mr. Xcoder May 9 '17 at 20:03
  • 1
    \$\begingroup\$ If you add . and another language, you can have 11. J: 2#.2+3*3 \$\endgroup\$ – Conor O'Brien May 9 '17 at 21:17
  • \$\begingroup\$ @WheatWizard here \$\endgroup\$ – Conor O'Brien May 9 '17 at 21:47
  • 1
    \$\begingroup\$ @WheatWizard FWIW, all valid J permutations \$\endgroup\$ – Conor O'Brien May 9 '17 at 21:48
  • \$\begingroup\$ @WheatWizard J is technically a REPL. Prefix the code with echo to see the output. \$\endgroup\$ – Conor O'Brien May 9 '17 at 21:50
11
\$\begingroup\$

1 language, 0 bytes, score 1

I don't know how high scores will get in this challenge, so let's take this spot.


Try it online!

In Retina, the empty program with no input prints 1.

Score = 1!/0! = 1/1 = 1

\$\endgroup\$
  • 7
    \$\begingroup\$ This looks at first glance like a joke answer, but has the highest score so far... \$\endgroup\$ – trichoplax May 9 '17 at 19:28
  • \$\begingroup\$ Same score for a 1 byte single language entry, no? \$\endgroup\$ – Adám May 9 '17 at 19:30
  • \$\begingroup\$ @Adám yeah, like 1 in R, for example \$\endgroup\$ – Giuseppe May 9 '17 at 19:32
  • 5
    \$\begingroup\$ In jelly, this outputs 0, so 2 languages => score=2 \$\endgroup\$ – Mr. Xcoder May 9 '17 at 19:34
  • 5
    \$\begingroup\$ @Mr.Xcoder No that is not how the scoring works. You must output 1 through n and each should be on a separate permutation. \$\endgroup\$ – Sriotchilism O'Zaic May 9 '17 at 19:53
6
\$\begingroup\$

2 languages, 2 bytes, score 1

Doesn't beat Leo's answer, but I thought I'd present a 2-language solution (well, and Wheat Wizard ninja'd a score-2 answer in between anyway).

Retina, prints 1

2`

Try it online!

This is essentially the same as Leo's empty program.

Pyth, prints 2

`2

Try it online!

This is repr(2) so it computes "2" which gets printed as 2.

\$\endgroup\$
5
\$\begingroup\$

26 languages, 46 bytes, Score : 1.68861953e-28 (0.000000000000000000000000000168861953)

All the languages are mainstream ones (i.e. they are actually used by people in development) and there's no REPL solution in any language. This answer is never going to win, but that's not a reason for not posting it...

//#**print()ale123456789+chous :f{}:""enttd *;

1. Python 2

print 1#//**()alechous:f{}:23456789+ ""enttd*;

Try it online!

2. Python 3

print(2)#//**alechous13456789+: f{}: ""enttd*;

Try it online!

3. Ruby

puts 3#//**()alecho:f12456789+{}rin: ""enttd*;

Try it online!

4. CoffeeScript

alert 4#//**()pinchous:12356789+f{}: ""enttd*;

Try it online!

5. PHP

echo 5/*alrt#()pinus:f{:12346789+} ""enttd;**/

Try it online!

6. Perl 5

print 6#/*ale()chous:12345789+f{:} */""enttd*;

Try it online!

7. Perl 6

print 7#/*ale)(chous:f12345689+{:} */""enttd*;

Try it online!

8. JavaScript (ES5)

alert(8)//pin 12345679+#*chous:f{:} *""enttd*;

Try it online!

9. JavaScript (ES6)

alert(9)//inp 12345678+#*chous: f{:}*""enttd*;

Try it online!

10. JavaScript (ES7)

alert(9+1)//pni #*chous2345678: f{:}*""enttd*;

Try it online!

11. Batch

echo 9+2 ::alrt()//pni#*usf{1345678}*""enttd*;

Couldn't find an online interpreter for this one. Try running this code in the Command Prompt, if you are on Windows.

12. Bash

echo 12 #::alrt(3456789+)//pni*usf{}*""enttd*;

Try it online!

13. CSS

*:after{content:"13" /*h# l(2456789+)pisud;*/}

Try it online!

14. Less

*:after{content:"14" /*#h l(2356789+)pisud;*/}

Try it online!

15. Stylus

*:after{content:"15" /*#hl (2346789+)pisud;*/}

Try it online!

16. TypeScript

alert(16)//inp #*chous2345789+: :{f}*""entt*d;

Try it online!

17. Octave

disp(17)#//n *chou2345689+: :{f}*""entt*alert;

Try it online!

18. Swift

print(18)//ds# *chou2345679+: :{f}""ent*ale*t;

Try it online!

19. Julia

print(19)#ds// *chou2345678+: :{f}""ent*ale*t;

Try it online!

20. Maxima

print(18+2);/*#ds ouch 345679::{f}""entale*t*/

Try it online!

21. Clojure

(print "21");/*#ds ouch3456789+::{f}entale*t*/

Try it online!

22. Groovy

print 19+3//();*#ds oh245678::{fuc*}entalet*""

Try it online!

23. CommonLisp

(print 23);//*#ds oh1456789+::{fuc*}entalet*""

Try it online!

24. EmacsLisp

(print 24);//*#ds oh1356789+::{fuc*}entalet*""

Try it online!

25. PicoLisp

(print 25);//*#ds oh1346789+::{fuc*}entalet*""

Try it online!

26. Logo

print 21+5 ;//*#dsoh346789::{fuc*}entalet*""()

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ And Swift, displaying 18: print(18)//#**alechous: f{}:2345679+ ""enttd* \$\endgroup\$ – Mr. Xcoder May 10 '17 at 10:23
  • \$\begingroup\$ Suppose this will increase your score by about 0.002e-20 :)) \$\endgroup\$ – Mr. Xcoder May 10 '17 at 10:30
  • 3
    \$\begingroup\$ pfft. 2017 will be the year of the Befunge Web Framework! \$\endgroup\$ – Skyler May 10 '17 at 13:28
  • \$\begingroup\$ Comments are just going to turn this entire question into insanity… \$\endgroup\$ – Mathime May 10 '17 at 19:32
  • \$\begingroup\$ btw Applescript which can be seen in my answer works without a REPL, but does require -- for comments. If you add -- you can probably also work in at least one type of haskell. \$\endgroup\$ – Sriotchilism O'Zaic May 11 '17 at 6:59
3
\$\begingroup\$

12 Languages, 16 Bytes - Score: 0.003

print(0b11000)#1

Prints 1 in 2sable

print(0b1100)#10

Print 10 in 05AB1E

print(0b11)#1000

Re-arranging the binary numbers prints 2-9, 11-12 in:

  • Crystal
  • Julia 0.5
  • J-uby
  • Lily
  • Perl 5
  • Perl 6
  • Python 3
  • Python 2
  • Python
  • Ruby

L=145297152000 12! = 479001600

I just used TiO for a list of valid languages for this (If these are all considered unique?). Removed some duplicate languages thanks to input from Wheat Wizard. This answer is looking pretty low, though I feel it has potential.

\$\endgroup\$
  • \$\begingroup\$ Julia 0.4 and 0.5 have the same major version number. And so does Python 2 (PyPy) and Python 2. However this will probably work in Python 1 \$\endgroup\$ – Sriotchilism O'Zaic May 9 '17 at 21:05
  • \$\begingroup\$ Can you leave off the print and call it repl? How many of these have repls? \$\endgroup\$ – Brian McCutchon May 10 '17 at 5:42
  • \$\begingroup\$ @BrianMcCutchon Lily, Perl, and Crystal do not have repls. All the other ones do. \$\endgroup\$ – Sriotchilism O'Zaic May 11 '17 at 7:09
1
\$\begingroup\$

JavaScript (ES6), Python 2, Python 3, Japt, 4.735e-15

# ()//1234=>inprt

ES6 (1)

p=>1//rint 234()#

Python 2 (2)

print 2#134=>//()

Python 3 (3)

print(3)# 124=>//

Japt (4)

#rint>=3/2)p (4/1
\$\endgroup\$
  • \$\begingroup\$ Your score is 4.73508590206e-15 btw. \$\endgroup\$ – Sriotchilism O'Zaic May 9 '17 at 19:22
  • \$\begingroup\$ Is it? 4 factorial is 24. That divided by 17 is roughly 1.4 \$\endgroup\$ – Luke May 9 '17 at 19:23
  • \$\begingroup\$ Not divided by 17 but by 5068545850368000, the number of ways to rearrange the string. \$\endgroup\$ – Sriotchilism O'Zaic May 9 '17 at 19:24
  • \$\begingroup\$ Oops. Misread that. Thanks for pointing it out. \$\endgroup\$ – Luke May 9 '17 at 19:25
  • \$\begingroup\$ @WheatWizard Ouch, I missed that too. \$\endgroup\$ – Adám May 9 '17 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.