Perl: ∞
$z.="-1,";$_.=A;END{$m.=!!s/./{${z}B}/g,map(/B/||s/\d+\K/,/g*/(-\d*,).*\1/||($n{$_}||=$m++),sort glob),print$n{$z}if/A/}
$z.="-2,";$_.=A;END{$m.=!!s/./{${z}B}/g,map(/B/||s/\d+\K/,/g*/(-\d*,).*\1/||($n{$_}||=$m++),sort glob),print$n{$z}if/A/}
$z.="-3,";$_.=A;END{$m.=!!s/./{${z}B}/g,map(/B/||s/\d+\K/,/g*/(-\d*,).*\1/||($n{$_}||=$m++),sort glob),print$n{$z}if/A/}
Extend to any length you like
Will quickly run out of memory since memory usage is like O(n^n). It would however be easy to replace the permutation indexer by O(n) code, just longer. I'm just illustrating the way you can use END{}
for this task in perl. All END{}
blocks run at exit time, but only the first one that get called (the one last in the code) will output anything due to the /A/
test which is only true once
Notice that the $m
counter must count as a string because as a number it would overflow (later than the end of the universe but it's the principle that counts). For the same reason I "count" the number of lines by constructing a string of A
s instead of using a real counter though this overflow would happen even later.
Another way to do this in perl:
@{$b.=A; if($a eq $b) {use bigint; $n=0;$n++for@F;$c=0;$c=$c*$n--+map{$z=$_;$a=grep$_&&$_>$z,@F;$_=0;}@F;print$c}}=()x push@F,"1".!($a.=A),
@{$b.=A; if($a eq $b) {use bigint; $n=0;$n++for@F;$c=0;$c=$c*$n--+map{$z=$_;$a=grep$_&&$_>$z,@F;$_=0;}@F;print$c}}=()x push@F,"2".!($a.=A),
@{$b.=A; if($a eq $b) {use bigint; $n=0;$n++for@F;$c=0;$c=$c*$n--+map{$z=$_;$a=grep$_&&$_>$z,@F;$_=0;}@F;print$c}}=()x push@F,"3".!($a.=A),
This uses that fact that in foo = bar
bar
is executed after foo
. This version by the way doesn't go crazy in time and space but that makes the code longer
Yet another idea is to use DESTROY
which has the advantage that only one of them will be executed. I'm not going to repeat the permutation indexing code of which I already gave two examples.
push@F,"1";bless\@F;DESTROY{print"Work out permutation index of @{$_[0]}\n" }
push@F,"2";bless\@F;DESTROY{print"Work out permutation index of @{$_[0]}\n" }
push@F,"3";bless\@F;DESTROY{print"Work out permutation index of @{$_[0]}\n" }
Or using BEGIN
:
BEGIN{push@F,"1"} print"Work out permutation index of @F\n"; exit;
BEGIN{push@F,"2"} print"Work out permutation index of @F\n"; exit;
BEGIN{push@F,"3"} print"Work out permutation index of @F\n"; exit;
3What about answers that present constructions which work for any
n
? Are they all tied at a score of ∞? – Martin Ender – 2018-02-08T21:00:38.837@MartinEnder Yes. ∞ is a fine score. If you find a construction like that then you win. – Post Rock Garf Hunter – 2018-02-08T21:01:49.947
@AdmBorkBork Yes each arrangement should output one number. Could that be clearer? – Post Rock Garf Hunter – 2018-02-08T21:02:31.590
How far will it be cut up? Down to individual bytes or individual words? – moonheart08 – 2018-02-08T21:02:47.690
@moonheart08 It just gets cut into lines no further. – Post Rock Garf Hunter – 2018-02-08T21:03:12.103
So what about programs that contain no newlines? :P – moonheart08 – 2018-02-08T21:03:53.207
@moonheart08 Then they have 1 line so they ought to output 1. – Post Rock Garf Hunter – 2018-02-08T21:04:34.180
Time for self replicaton, then. :) – moonheart08 – 2018-02-08T21:06:01.510
Full program or..? – totallyhuman – 2018-02-08T21:06:23.787
1@totallyhuman Standard output rules for whatever language you are using. I'll update the question to be completely clear on this. – Post Rock Garf Hunter – 2018-02-08T21:07:49.823
Is there a tie-breaker? Otherwise Martin's answer is final. – Erik the Outgolfer – 2018-02-08T21:10:37.507
1@EriktheOutgolfer No tie breaker. Martin may have found a way to score infinity in CJam but there are plenty of other languages to try on. – Post Rock Garf Hunter – 2018-02-08T21:11:29.203
Why not have length (in bytes) of the shortest line be the tie breaker? – dylnan – 2018-02-09T00:03:02.360
Why must you make this impossible for brain-flak :( – Christopher – 2018-02-09T02:25:23.840
@Christopher It's certainly not impossible in Brain-Flak. You can definitely port the CJam method to Brain-Flak. – Post Rock Garf Hunter – 2018-02-09T02:26:47.647
@WheatWizard I actually have a super golfy solution that works with infinity score but there appears to be a bug in the interpreter – Christopher – 2018-02-09T02:59:43.917
gahh turns out my idea was wrong lol – Christopher – 2018-02-09T19:07:53.107
I think I did it! – Christopher – 2018-02-09T19:22:11.160