5 languages 11 characters = 0.4545
Took this challenge as an opportunity to check out some new languages (CJam, Burlesque, zsh, gs2). First time I've worked with these languages.
The method behind creating the output is different in nearly each language. Only the CJam and the gs2 method are identical. The 4 methods are, creating a range [1, 100] and slice it with modulo (CJam and gs2), creating the range [1, ..., 100] and filter for elements that are 1 mod 7 (Pyth), creating the range [1, ..., 100], divide it into chunks of len 7 and use the first element of each chunk (Burlesque), and creating the sequence directly (zsh).
I tried to design each program in such a way, that it looks golfed to someone, who is not familiar with the language.
edit 1: added Burlesque, previous 2 languages with 10 characters = 0.2
edit 2: added gs2, previous 3 languages with 11 characters = 0.2727
edit 3: added zsh, previous 4 languages with 11 characters = 0.3636
CJam
q~\1+,0-\%p
Test it online with the input 100 7
.
q~ push the evaluated input (100 7)
\ swap (7 100)
1 push 1 (7 100 1)
+ add last to elements (7 101)
, create the range (7, [0, 1, ..., 100])
0 push 0 (7, [0, 1, ..., 100], 0)
- delete 0 from the range (7, [1, 2, ..., 100])
\ swap ([1, 2, ..., 100], 7)
% use every 7th entry ([1, 8, ..., 99])
p print pretty
Burlesque
jrojcoq-]m[
Beside zsh, this is the only golfed program. Burlesque is quite awesome, it has a very large range of different functions, like ro
. Sadly there's nothing like the Python [::a]
slicing operator.
There is no online interpreter, but you can get Burlesque here. Since Burlesque doesn't support functions or IO, you have to put the values onto the stack first, like 100 7 jrojcoq-]m[
j Swap (7 100)
ro Range (7 {1 2 ... 100})
j Swap ({1 2 ... 100} 7)
co ChunksOf ({{1 2 .. 7} {8 ... 14} ... {99 100}})
q Create Block ({{1 2 .. 7} {8 ... 14} ... {99 100}} {})
-] head (first element) ({{1 2 .. 7} {8 ... 14} ... {99 100}} {-]})
m[ map the chunks to the head-block
gs2
read-nums dup head inc range tail swap reverse head mod unlines
Yep, this is only 11 chars. In gs2 each byte has a different meaning. But because writing in bytes is quite hard and not any fun, you can also write in mnemonics, which you can compile to the actual gs2 code. The gs2 code, which gets executed is
W@!'."B !4+
or as hex-dump:
57 40 21 27 2e 22 42 20 21 34 2b
Fun fact: I didn't write in mnemonics, but directly the numbers of the hex-dump.
You can test it by downloading the compiler. Compile the mnemonics file with python gs2c.py < mnemonics.txt > compiled
or simply copy W@!'."B !4+
to a file named compiled
and then execute it with echo 100 7 | python gs2.py compiled
.
The mnemonics is pretty self explainable, but here's what's going on in the stack.
57 40 21 27 2e 22 42 20 21 34 2b
57 read-nums ([100 7])
40 dup ([100 7] [100 7])
21 head ([100 7] 100)
27 inc ([100 7] 101)
2e range ([100 7] [0 1 ... 100])
22 tail ([100 7] [1 2 ... 100])
42 swap ([1 2 ... 100] [100 7])
20 reverse ([1 2 ... 100] [7 100])
21 head ([1 2 ... 100] 7)
34 mod ([1 8 ... 99])
2b unlines ('1\n8\n...\n99')
everything on the stack gets printed
Btw, 8 bytes are possible, maybe even less.
edit: I forked gs2, slightly manipulated a command and made a pull request, which is already merged. So now the task can be done with 6 bytes: read-nums extract-array swap range1 mod unlines
, which translates to 57 0e 42 2f 34 2b
, which is even better than the optimal pyth.
zsh
f() seq 1 $2 $1
This defines a function f
, that creates the a sequence. To use it on Windows, I installed the babun shell, where you can simply type these commands. Simply write f() seq 1 $2 $1
and in the next line f 100 7
.
First I tried to write this in Bash, but there you have to write ()
around the code block, like f() ( seq 1 $2 $1 )
. So I switched to zsh instead.
Pyth
fq1%TeQUhhQ
This really hurts, since of course I see the obvious 7 byte golf. You can test it online with the input 100, 7
.
Q = input()
UhhQ the range [0, 1, ..., Q[0]]
f filtered (only use those elements T, which satisfy the equation
q1%TeQ 1 == T % Q[1]
NumberOfLanguages / CodeSize
? \$\endgroup\$