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]
Does simply padding out the code with spaces count...? Or simply using the most obtuse variable or function names...? – deceze – 2015-02-23T03:21:05.843
@deceze Should've thought of that before. Just edited in some things under the twist. spaces do not count and function/variable names have a 10 character limit – michaelpri – 2015-02-23T03:27:33.323
It still just becomes a competition of adding some useless padding to fulfil the criteria. E.g., just add
"aaaaaaaaaa..";
at the end of every program, which is a valid noop in virtually all languages... – deceze – 2015-02-23T03:29:04.903@deceze I see. I made it code golf also, so people will try to keep it short (hopefully). – michaelpri – 2015-02-23T03:33:57.393
1Maybe score by
NumberOfLanguages / CodeSize
? – Ypnypn – 2015-02-23T04:01:40.133@Ypnypn I can't believe I didn't think of that before. Thanks – michaelpri – 2015-02-23T04:03:42.173
@michaelpri I think you cam remove the "all programs must be the same size" requirement since you've changed the scoring rules. Edit: I must also warn that NumberOfLanguages/Votes will simply encourage responses in a single language. – PhiNotPi – 2015-02-23T04:13:34.310
1@PhiNotPi I think the "all programs must be the same size" still adds a lot to the contest. – Ypnypn – 2015-02-23T05:04:25.573
5I think this is still flawed. If I answer only in Whitespace, I get a score of 1/0, i.e. infinity. Otherwise, I'm still better off answering in a single language where this is shortest, because adding any other language (with longer code), reduces my score. – Martin Ender – 2015-02-23T06:38:37.240
Are these snippets/functions or whole working programs? – HEGX64 – 2015-02-23T06:47:44.100
@MartinBüttner I would assume whitespace reverses the whitespace rule so only whitespace counts. – captncraig – 2015-02-23T07:44:18.997
I recommend using the sandbox next time, so these issues can be sorted out before the challenge is posted on main.
– Martin Ender – 2015-02-23T07:54:33.957@captncraig I haven't heard of this being a common policy. But then there's still Lenguage.
– Martin Ender – 2015-02-23T07:55:13.730How about you amend the scoring rules not to disregard whitespace but to forbid snippets that can be reduced in size trivially where trivial means that no snippet that comes from the posted snippet with some characters removed may solve the task? – FUZxxl – 2015-02-23T09:50:34.077
For instance, for the task return 2,
return 0+2;
could be reduced trivially toreturn 2;
butreturn 1+1;
can't since you cannot remove some characters with the effect remaining. – FUZxxl – 2015-02-23T09:51:50.897@MartinBüttner How so? In my model whitespace do count towards the score and as far as I know no programming language exists where the empty program has the required semantics. – FUZxxl – 2015-02-23T09:57:09.907
1Also, your point about having longer programs reduces your score is incorrect. If I post one program of length 10, my score is 0.1. If I post three programs of length 20, my score is 0.15, which is higher. Shorter code size doesn't mean higher score automatically. – FUZxxl – 2015-02-23T09:59:24.667
@FUZxxl, oh I misunderstood the scoring... I thought it was divided by total code size, not the code size of each snippet. That should work then, although it will be hard to verify if submissions satisfy your rules. – Martin Ender – 2015-02-23T10:00:57.790
5-1 for disincentivising just throwing in obscure verbose languages for the fun of it, in a [rosetta-stone]. – algorithmshark – 2015-02-23T16:34:56.757
n
must be >=2
, otherwise,s
is zero, which doesn't work. – mbomb007 – 2015-02-25T21:17:18.623@mbomb007 Good point didn't think of that, – michaelpri – 2015-02-25T21:18:30.587
This challenge has prompted me to delve into many languages in the last 2 days. My brain hurts... – mbomb007 – 2015-02-25T22:17:18.940
Why not change scoring to
numberOfLanguages/longestCodeSize
? Everyone seems to be padding their shorter codes to match their longest, this will not change scoring only readability. – freekvd – 2015-02-26T13:39:37.693