Find permutation with highest organization number (OEIS A047838)Permutations[Range[12]] produces an error instead of a listCombining nested lists that meet certain criteria for a permutationEfficient submatrix swaps for large sparse matrixFinding the optimal teams ranking based on the table of match resultsUsing Permutations to create numbersPermutation with a conditionNumber by permutationDelete redundant x,y pairsFinding integers that do not appear on listFind permutation index

How to deal with a colleague who is being aggressive?

What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?

includegraphics: get the "scale" value of a figure whose size is expressed by "width"

On San Andreas Speedruns, why do players blow up the Picador in the mission Ryder?

What is the use case for non-breathable waterproof pants?

Public transport tickets in UK for two weeks

Did this character show any indication of wanting to rule before S8E6?

Is it possible to remotely hack the GPS system and disable GPS service worldwide?

Can a wizard copy a spell without first identifying it?

Is this statement about cut time correct?

Is superuser the same as root?

How to politely tell someone they did not hit "reply to all" in an email?

Where is Jon going?

Why do Russians almost not use verbs of possession akin to "have"?

How can I make an argument that my time is valuable?

Natural Armour and Weapons

Are black holes spherical during merger?

Are runways booked by airlines to land their planes?

Find this cartoon

Count all vowels in string

Expected maximum number of unpaired socks

Time complexity of an algorithm: Is it important to state the base of the logarithm?

What was the idiom for something that we take without a doubt?

I know that there is a preselected candidate for a position to be filled at my department. What should I do?



Find permutation with highest organization number (OEIS A047838)


Permutations[Range[12]] produces an error instead of a listCombining nested lists that meet certain criteria for a permutationEfficient submatrix swaps for large sparse matrixFinding the optimal teams ranking based on the table of match resultsUsing Permutations to create numbersPermutation with a conditionNumber by permutationDelete redundant x,y pairsFinding integers that do not appear on listFind permutation index













4












$begingroup$


OEIS A047838 defines the "organization number" of a permutation as:




Define the organization number of a permutation pi_1, pi_2, ..., pi_n
to be the following. Start at 1, count the steps to reach 2, then the
steps to reach 3, etc. Add them up. Then the maximal value of the
organization number of any permutation of [1..n] for n = 0, 1, 2, 3,
... is given by 0, 1, 3, 7, 11, 17, 23, ... (this sequence).




The phrase "organization number" appears to be nonstandard, but I'll
continue to use it in this question.



In Mathematica, the organization number of a permutation would be:



orgNumber[list_] := 
Total[Table[Abs[list[[i]] - list[[i-1]]], i,2,Length[list]]];


Of course, that works for any list, not just permutations.



The OEIS link above provides a formula for the highest possible
organization number for a permutation of $n$ elements:



maxOrg[n_] = Floor[n^2/2]-1


My question: how can I find a permutation of $n$ elements whose
organization number is maximal. For $n > 1$, there will always be at
least 2 such permutations (since the reverse permutation has the same
organization number), and, from what I've seen, there are usually
several. I just want to find one of them.



For small values of $n$, you can brute force it:



maxPerm[n_] := Select[Permutations[Range[1,n]], orgNumber[#] == maxOrg[n] &]


but this gets really slow after about $n=10$.



I looked at the "first" permutation meeting this condition for each
value of $n=2$ through $n=8$ and got:



1, 2
1, 3, 2
2, 4, 1, 3
2, 4, 1, 5, 3
3, 5, 1, 6, 2, 4
3, 5, 1, 6, 2, 7, 4
4, 6, 1, 7, 2, 8, 3, 5


Going from an even number to an odd number seems to follow an obvious
pattern, so I correctly guessed the following for $n=9$:



4, 6, 1, 7, 2, 8, 3, 9, 5


However, I couldn't find enough of a pattern to find a value for $n=10$.



In my "real world" application, $n = 44$, so brute forcing is not an option.



However, I did use:



t0 = Table[RandomSample[Range[44]], i, 1, 100000];
t1 = Max[Map[orgNumber, t0]]


Obviously, results will vary, but I got $t1 = 885$. Since the max
possible is 967, this is a pretty good value (and I get the
permutation(s) matching this number using Select, as above), but,
obviously, I'd prefer the true max.



Another interesting question would be: what's the distribution of
organization numbers for a given $n$.



Based on my random experimentation, the distribution appears to look
somewhat Normal, with a mean of $n^2/3$. I wasn't able to get a real
feeling for the standard deviation, though it appears to be about 59.6
for $n=44$.










share|improve this question











$endgroup$







  • 2




    $begingroup$
    orgNumber[list_] := Total@Abs@Differences@list should be much faster.
    $endgroup$
    – Carl Woll
    7 hours ago










  • $begingroup$
    Thanks, I forgot about Differences. I'll leave things as is in the code since I know the code I posted is working, and, even with this speed increase, I think large n will still be a problem.
    $endgroup$
    – barrycarter
    7 hours ago






  • 1




    $begingroup$
    I don't think you've interpreted this correctly. I believe the correct function for the result is Tr@Abs@Differences@Ordering@res where res is a permutation. A maximal example is then simply generated instantly via Join[Range[2, 2 Floor[#/2], 2], 1, Range[2 Ceiling[#/2] - 1, 3, -2]] & with argument of n desired. The results match OEIS.
    $endgroup$
    – ciao
    3 hours ago










  • $begingroup$
    @J42161217 pernaps, but it then has nothing to do with the OP title nor the oeis sequence.
    $endgroup$
    – ciao
    3 hours ago






  • 1




    $begingroup$
    @ciao Yes! you are right. Ordering@res is the right answer.
    $endgroup$
    – J42161217
    2 hours ago















4












$begingroup$


OEIS A047838 defines the "organization number" of a permutation as:




Define the organization number of a permutation pi_1, pi_2, ..., pi_n
to be the following. Start at 1, count the steps to reach 2, then the
steps to reach 3, etc. Add them up. Then the maximal value of the
organization number of any permutation of [1..n] for n = 0, 1, 2, 3,
... is given by 0, 1, 3, 7, 11, 17, 23, ... (this sequence).




The phrase "organization number" appears to be nonstandard, but I'll
continue to use it in this question.



In Mathematica, the organization number of a permutation would be:



orgNumber[list_] := 
Total[Table[Abs[list[[i]] - list[[i-1]]], i,2,Length[list]]];


Of course, that works for any list, not just permutations.



The OEIS link above provides a formula for the highest possible
organization number for a permutation of $n$ elements:



maxOrg[n_] = Floor[n^2/2]-1


My question: how can I find a permutation of $n$ elements whose
organization number is maximal. For $n > 1$, there will always be at
least 2 such permutations (since the reverse permutation has the same
organization number), and, from what I've seen, there are usually
several. I just want to find one of them.



For small values of $n$, you can brute force it:



maxPerm[n_] := Select[Permutations[Range[1,n]], orgNumber[#] == maxOrg[n] &]


but this gets really slow after about $n=10$.



I looked at the "first" permutation meeting this condition for each
value of $n=2$ through $n=8$ and got:



1, 2
1, 3, 2
2, 4, 1, 3
2, 4, 1, 5, 3
3, 5, 1, 6, 2, 4
3, 5, 1, 6, 2, 7, 4
4, 6, 1, 7, 2, 8, 3, 5


Going from an even number to an odd number seems to follow an obvious
pattern, so I correctly guessed the following for $n=9$:



4, 6, 1, 7, 2, 8, 3, 9, 5


However, I couldn't find enough of a pattern to find a value for $n=10$.



In my "real world" application, $n = 44$, so brute forcing is not an option.



However, I did use:



t0 = Table[RandomSample[Range[44]], i, 1, 100000];
t1 = Max[Map[orgNumber, t0]]


Obviously, results will vary, but I got $t1 = 885$. Since the max
possible is 967, this is a pretty good value (and I get the
permutation(s) matching this number using Select, as above), but,
obviously, I'd prefer the true max.



Another interesting question would be: what's the distribution of
organization numbers for a given $n$.



Based on my random experimentation, the distribution appears to look
somewhat Normal, with a mean of $n^2/3$. I wasn't able to get a real
feeling for the standard deviation, though it appears to be about 59.6
for $n=44$.










share|improve this question











$endgroup$







  • 2




    $begingroup$
    orgNumber[list_] := Total@Abs@Differences@list should be much faster.
    $endgroup$
    – Carl Woll
    7 hours ago










  • $begingroup$
    Thanks, I forgot about Differences. I'll leave things as is in the code since I know the code I posted is working, and, even with this speed increase, I think large n will still be a problem.
    $endgroup$
    – barrycarter
    7 hours ago






  • 1




    $begingroup$
    I don't think you've interpreted this correctly. I believe the correct function for the result is Tr@Abs@Differences@Ordering@res where res is a permutation. A maximal example is then simply generated instantly via Join[Range[2, 2 Floor[#/2], 2], 1, Range[2 Ceiling[#/2] - 1, 3, -2]] & with argument of n desired. The results match OEIS.
    $endgroup$
    – ciao
    3 hours ago










  • $begingroup$
    @J42161217 pernaps, but it then has nothing to do with the OP title nor the oeis sequence.
    $endgroup$
    – ciao
    3 hours ago






  • 1




    $begingroup$
    @ciao Yes! you are right. Ordering@res is the right answer.
    $endgroup$
    – J42161217
    2 hours ago













4












4








4


2



$begingroup$


OEIS A047838 defines the "organization number" of a permutation as:




Define the organization number of a permutation pi_1, pi_2, ..., pi_n
to be the following. Start at 1, count the steps to reach 2, then the
steps to reach 3, etc. Add them up. Then the maximal value of the
organization number of any permutation of [1..n] for n = 0, 1, 2, 3,
... is given by 0, 1, 3, 7, 11, 17, 23, ... (this sequence).




The phrase "organization number" appears to be nonstandard, but I'll
continue to use it in this question.



In Mathematica, the organization number of a permutation would be:



orgNumber[list_] := 
Total[Table[Abs[list[[i]] - list[[i-1]]], i,2,Length[list]]];


Of course, that works for any list, not just permutations.



The OEIS link above provides a formula for the highest possible
organization number for a permutation of $n$ elements:



maxOrg[n_] = Floor[n^2/2]-1


My question: how can I find a permutation of $n$ elements whose
organization number is maximal. For $n > 1$, there will always be at
least 2 such permutations (since the reverse permutation has the same
organization number), and, from what I've seen, there are usually
several. I just want to find one of them.



For small values of $n$, you can brute force it:



maxPerm[n_] := Select[Permutations[Range[1,n]], orgNumber[#] == maxOrg[n] &]


but this gets really slow after about $n=10$.



I looked at the "first" permutation meeting this condition for each
value of $n=2$ through $n=8$ and got:



1, 2
1, 3, 2
2, 4, 1, 3
2, 4, 1, 5, 3
3, 5, 1, 6, 2, 4
3, 5, 1, 6, 2, 7, 4
4, 6, 1, 7, 2, 8, 3, 5


Going from an even number to an odd number seems to follow an obvious
pattern, so I correctly guessed the following for $n=9$:



4, 6, 1, 7, 2, 8, 3, 9, 5


However, I couldn't find enough of a pattern to find a value for $n=10$.



In my "real world" application, $n = 44$, so brute forcing is not an option.



However, I did use:



t0 = Table[RandomSample[Range[44]], i, 1, 100000];
t1 = Max[Map[orgNumber, t0]]


Obviously, results will vary, but I got $t1 = 885$. Since the max
possible is 967, this is a pretty good value (and I get the
permutation(s) matching this number using Select, as above), but,
obviously, I'd prefer the true max.



Another interesting question would be: what's the distribution of
organization numbers for a given $n$.



Based on my random experimentation, the distribution appears to look
somewhat Normal, with a mean of $n^2/3$. I wasn't able to get a real
feeling for the standard deviation, though it appears to be about 59.6
for $n=44$.










share|improve this question











$endgroup$




OEIS A047838 defines the "organization number" of a permutation as:




Define the organization number of a permutation pi_1, pi_2, ..., pi_n
to be the following. Start at 1, count the steps to reach 2, then the
steps to reach 3, etc. Add them up. Then the maximal value of the
organization number of any permutation of [1..n] for n = 0, 1, 2, 3,
... is given by 0, 1, 3, 7, 11, 17, 23, ... (this sequence).




The phrase "organization number" appears to be nonstandard, but I'll
continue to use it in this question.



In Mathematica, the organization number of a permutation would be:



orgNumber[list_] := 
Total[Table[Abs[list[[i]] - list[[i-1]]], i,2,Length[list]]];


Of course, that works for any list, not just permutations.



The OEIS link above provides a formula for the highest possible
organization number for a permutation of $n$ elements:



maxOrg[n_] = Floor[n^2/2]-1


My question: how can I find a permutation of $n$ elements whose
organization number is maximal. For $n > 1$, there will always be at
least 2 such permutations (since the reverse permutation has the same
organization number), and, from what I've seen, there are usually
several. I just want to find one of them.



For small values of $n$, you can brute force it:



maxPerm[n_] := Select[Permutations[Range[1,n]], orgNumber[#] == maxOrg[n] &]


but this gets really slow after about $n=10$.



I looked at the "first" permutation meeting this condition for each
value of $n=2$ through $n=8$ and got:



1, 2
1, 3, 2
2, 4, 1, 3
2, 4, 1, 5, 3
3, 5, 1, 6, 2, 4
3, 5, 1, 6, 2, 7, 4
4, 6, 1, 7, 2, 8, 3, 5


Going from an even number to an odd number seems to follow an obvious
pattern, so I correctly guessed the following for $n=9$:



4, 6, 1, 7, 2, 8, 3, 9, 5


However, I couldn't find enough of a pattern to find a value for $n=10$.



In my "real world" application, $n = 44$, so brute forcing is not an option.



However, I did use:



t0 = Table[RandomSample[Range[44]], i, 1, 100000];
t1 = Max[Map[orgNumber, t0]]


Obviously, results will vary, but I got $t1 = 885$. Since the max
possible is 967, this is a pretty good value (and I get the
permutation(s) matching this number using Select, as above), but,
obviously, I'd prefer the true max.



Another interesting question would be: what's the distribution of
organization numbers for a given $n$.



Based on my random experimentation, the distribution appears to look
somewhat Normal, with a mean of $n^2/3$. I wasn't able to get a real
feeling for the standard deviation, though it appears to be about 59.6
for $n=44$.







filtering permutation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 hours ago









Roman

9,01511440




9,01511440










asked 8 hours ago









barrycarterbarrycarter

1,232823




1,232823







  • 2




    $begingroup$
    orgNumber[list_] := Total@Abs@Differences@list should be much faster.
    $endgroup$
    – Carl Woll
    7 hours ago










  • $begingroup$
    Thanks, I forgot about Differences. I'll leave things as is in the code since I know the code I posted is working, and, even with this speed increase, I think large n will still be a problem.
    $endgroup$
    – barrycarter
    7 hours ago






  • 1




    $begingroup$
    I don't think you've interpreted this correctly. I believe the correct function for the result is Tr@Abs@Differences@Ordering@res where res is a permutation. A maximal example is then simply generated instantly via Join[Range[2, 2 Floor[#/2], 2], 1, Range[2 Ceiling[#/2] - 1, 3, -2]] & with argument of n desired. The results match OEIS.
    $endgroup$
    – ciao
    3 hours ago










  • $begingroup$
    @J42161217 pernaps, but it then has nothing to do with the OP title nor the oeis sequence.
    $endgroup$
    – ciao
    3 hours ago






  • 1




    $begingroup$
    @ciao Yes! you are right. Ordering@res is the right answer.
    $endgroup$
    – J42161217
    2 hours ago












  • 2




    $begingroup$
    orgNumber[list_] := Total@Abs@Differences@list should be much faster.
    $endgroup$
    – Carl Woll
    7 hours ago










  • $begingroup$
    Thanks, I forgot about Differences. I'll leave things as is in the code since I know the code I posted is working, and, even with this speed increase, I think large n will still be a problem.
    $endgroup$
    – barrycarter
    7 hours ago






  • 1




    $begingroup$
    I don't think you've interpreted this correctly. I believe the correct function for the result is Tr@Abs@Differences@Ordering@res where res is a permutation. A maximal example is then simply generated instantly via Join[Range[2, 2 Floor[#/2], 2], 1, Range[2 Ceiling[#/2] - 1, 3, -2]] & with argument of n desired. The results match OEIS.
    $endgroup$
    – ciao
    3 hours ago










  • $begingroup$
    @J42161217 pernaps, but it then has nothing to do with the OP title nor the oeis sequence.
    $endgroup$
    – ciao
    3 hours ago






  • 1




    $begingroup$
    @ciao Yes! you are right. Ordering@res is the right answer.
    $endgroup$
    – J42161217
    2 hours ago







2




2




$begingroup$
orgNumber[list_] := Total@Abs@Differences@list should be much faster.
$endgroup$
– Carl Woll
7 hours ago




$begingroup$
orgNumber[list_] := Total@Abs@Differences@list should be much faster.
$endgroup$
– Carl Woll
7 hours ago












$begingroup$
Thanks, I forgot about Differences. I'll leave things as is in the code since I know the code I posted is working, and, even with this speed increase, I think large n will still be a problem.
$endgroup$
– barrycarter
7 hours ago




$begingroup$
Thanks, I forgot about Differences. I'll leave things as is in the code since I know the code I posted is working, and, even with this speed increase, I think large n will still be a problem.
$endgroup$
– barrycarter
7 hours ago




1




1




$begingroup$
I don't think you've interpreted this correctly. I believe the correct function for the result is Tr@Abs@Differences@Ordering@res where res is a permutation. A maximal example is then simply generated instantly via Join[Range[2, 2 Floor[#/2], 2], 1, Range[2 Ceiling[#/2] - 1, 3, -2]] & with argument of n desired. The results match OEIS.
$endgroup$
– ciao
3 hours ago




$begingroup$
I don't think you've interpreted this correctly. I believe the correct function for the result is Tr@Abs@Differences@Ordering@res where res is a permutation. A maximal example is then simply generated instantly via Join[Range[2, 2 Floor[#/2], 2], 1, Range[2 Ceiling[#/2] - 1, 3, -2]] & with argument of n desired. The results match OEIS.
$endgroup$
– ciao
3 hours ago












$begingroup$
@J42161217 pernaps, but it then has nothing to do with the OP title nor the oeis sequence.
$endgroup$
– ciao
3 hours ago




$begingroup$
@J42161217 pernaps, but it then has nothing to do with the OP title nor the oeis sequence.
$endgroup$
– ciao
3 hours ago




1




1




$begingroup$
@ciao Yes! you are right. Ordering@res is the right answer.
$endgroup$
– J42161217
2 hours ago




$begingroup$
@ciao Yes! you are right. Ordering@res is the right answer.
$endgroup$
– J42161217
2 hours ago










2 Answers
2






active

oldest

votes


















1












$begingroup$

...and we are done!

Solution for k=44 in 10 seconds



k=44;
r=Last@Select[Flatten[Table[Select[Riffle[#,-Last@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2],Floor[(k-1)/2],b=Range[s=Floor[Floor[(Floor[k^2/2]-1)/2]/Floor[k/2]],s+2]]]&/@Reverse/@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2]+1,Ceiling[(k-1)/2],Range[s=Floor[Floor[(Floor[k^2/2] - 1)/2]/Floor[k/2]],s+k-8]],Union[FoldList[Total[##]&,p,#]]==Range@k&],p,k],1],Union@Differences@Union[FoldList[Total[##]&,#[[1]],#]]==1&];w=FoldList[Total[##]&,1,r];
f=w+k-Max@w
Total@Abs@Differences@f
Floor[k^2/2]-1



k=44



22,44,21,43,20,42,19,41,18,40,17,39,16,38,15,37,14,36,13,35,12,34,11,33,10,32,9,31,8,30,7,29,6,28,5,27,4,26,3,25,2,24,1,23

967

967




This algorithm tries to find the differences-list of the result.



By examining the differences we can see that half of them are positive and half negative. Also sum of positives is equal to sum of negatives +1 and they are riffled.
So we are trying to produce those two sets using IntegerPartition but we must choose as less results as possible in order for this to terminate. In order to make this work we have to "fine-tune" the variable c of the following algorithm
(otherwise it will throw errors). The goal of this answer was to reach k=44 which seemed impossible by testing permutations...

Here are the correct values in order to hit k=50



k=50;
c=15;
r=Last@Select[Flatten[Table[Select[Riffle[#,-Last@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2],Floor[(k-1)/2],b=Range[s=Floor[Floor[(Floor[k^2/2]-1)/2]/Floor[k/2]],s+2]]]&/@Reverse/@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2]+1,Ceiling[(k-1)/2],Range[s=Floor[Floor[(Floor[k^2/2] - 1)/2]/Floor[k/2]],s+c]],Union[FoldList[Total[##]&,p,#]]==Range@k&],p,k],1],Union@Differences@Union[FoldList[Total[##]&,#[[1]],#]]==1&];w=FoldList[Total[##]&,1,r];
f=w+k-Max@w
Total@Abs@Differences@f
Floor[k^2/2]-1



k=50

25,50,24,49,23,48,22,47,21,46,20,45,19,44,18,43,17,42,16,41,15,40,14,39,13,38,12,37,11,36,10,35,9,34,8,33,7,32,6,31,5,30,4,29,3,28,2,27,1,26

1249

1249







share|improve this answer











$endgroup$












  • $begingroup$
    Shiny! Any chance you could explain it? It looks like you don't user Permutations, but instead IntegerPartitions to find which integers add up to the magic number? And then what?
    $endgroup$
    – barrycarter
    5 hours ago










  • $begingroup$
    Actually I studied the differences and tried to produce differences that work. Right now I'm working on some modifications... I let you know
    $endgroup$
    – J42161217
    5 hours ago










  • $begingroup$
    Wow! Would still be nice to understand the thought process, but that definitely answers the question.
    $endgroup$
    – barrycarter
    4 hours ago










  • $begingroup$
    Is there a copy error here? I''m not about to debug the jumble, but as is it blows up with a stream of errors under 12 and 11.3 MMA on my machine.
    $endgroup$
    – ciao
    4 hours ago










  • $begingroup$
    Read my comments to OP: I believe they have misinterpreted the OEIS entry, and generation is much simpler.
    $endgroup$
    – ciao
    3 hours ago


















4












$begingroup$

This answer just shows how to improve the speed of orgNumber:



orgNumber2[p_] := Total @ Abs @ Differences @ p


Comparison:



t0 = Table[RandomSample[Range[44]],i,1,100000];

t1 = Max[Map[orgNumber,t0]]; //AbsoluteTiming
t2 = Max[Map[orgNumber2, t0]]; //AbsoluteTiming

t1==t2



6.94362, Null



0.4978, Null



True




Another almost order of magnitude increase in speed can be obtained by writing a version that works with multiple lists:



orgNumber3[p:__List] := Total[Abs @ Transpose @ Differences[Transpose@p], 2]


Timing:



t3 = Max @ orgNumber3[t0]; //AbsoluteTiming
t1 == t2 == t3



0.070115, Null



True




Addendum



Using ciao's comment, producing the desired permutation is simple:



maxPerm[n_] := Ordering @ Join[
Range[2, 2 Floor[n/2], 2],
1,
Range[2 Ceiling[n/2] - 1, 3, -2]
]


For $n=44$:



r = maxPerm[44]; //AbsoluteTiming
r
orgNumber2[r]



0.000045, Null



23, 1, 44, 2, 43, 3, 42, 4, 41, 5, 40, 6, 39, 7, 38, 8, 37, 9, 36,
10, 35, 11, 34, 12, 33, 13, 32, 14, 31, 15, 30, 16, 29, 17, 28, 18,
27, 19, 26, 20, 25, 21, 24, 22



967




For $n = 10^6$ :



n = 10^6;
r = maxPerm[n]; //AbsoluteTiming
orgNumber2[r]
Floor[n^2/2] - 1



0.019479, Null



499999999999



499999999999







share|improve this answer











$endgroup$













    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f198888%2ffind-permutation-with-highest-organization-number-oeis-a047838%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1












    $begingroup$

    ...and we are done!

    Solution for k=44 in 10 seconds



    k=44;
    r=Last@Select[Flatten[Table[Select[Riffle[#,-Last@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2],Floor[(k-1)/2],b=Range[s=Floor[Floor[(Floor[k^2/2]-1)/2]/Floor[k/2]],s+2]]]&/@Reverse/@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2]+1,Ceiling[(k-1)/2],Range[s=Floor[Floor[(Floor[k^2/2] - 1)/2]/Floor[k/2]],s+k-8]],Union[FoldList[Total[##]&,p,#]]==Range@k&],p,k],1],Union@Differences@Union[FoldList[Total[##]&,#[[1]],#]]==1&];w=FoldList[Total[##]&,1,r];
    f=w+k-Max@w
    Total@Abs@Differences@f
    Floor[k^2/2]-1



    k=44



    22,44,21,43,20,42,19,41,18,40,17,39,16,38,15,37,14,36,13,35,12,34,11,33,10,32,9,31,8,30,7,29,6,28,5,27,4,26,3,25,2,24,1,23

    967

    967




    This algorithm tries to find the differences-list of the result.



    By examining the differences we can see that half of them are positive and half negative. Also sum of positives is equal to sum of negatives +1 and they are riffled.
    So we are trying to produce those two sets using IntegerPartition but we must choose as less results as possible in order for this to terminate. In order to make this work we have to "fine-tune" the variable c of the following algorithm
    (otherwise it will throw errors). The goal of this answer was to reach k=44 which seemed impossible by testing permutations...

    Here are the correct values in order to hit k=50



    k=50;
    c=15;
    r=Last@Select[Flatten[Table[Select[Riffle[#,-Last@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2],Floor[(k-1)/2],b=Range[s=Floor[Floor[(Floor[k^2/2]-1)/2]/Floor[k/2]],s+2]]]&/@Reverse/@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2]+1,Ceiling[(k-1)/2],Range[s=Floor[Floor[(Floor[k^2/2] - 1)/2]/Floor[k/2]],s+c]],Union[FoldList[Total[##]&,p,#]]==Range@k&],p,k],1],Union@Differences@Union[FoldList[Total[##]&,#[[1]],#]]==1&];w=FoldList[Total[##]&,1,r];
    f=w+k-Max@w
    Total@Abs@Differences@f
    Floor[k^2/2]-1



    k=50

    25,50,24,49,23,48,22,47,21,46,20,45,19,44,18,43,17,42,16,41,15,40,14,39,13,38,12,37,11,36,10,35,9,34,8,33,7,32,6,31,5,30,4,29,3,28,2,27,1,26

    1249

    1249







    share|improve this answer











    $endgroup$












    • $begingroup$
      Shiny! Any chance you could explain it? It looks like you don't user Permutations, but instead IntegerPartitions to find which integers add up to the magic number? And then what?
      $endgroup$
      – barrycarter
      5 hours ago










    • $begingroup$
      Actually I studied the differences and tried to produce differences that work. Right now I'm working on some modifications... I let you know
      $endgroup$
      – J42161217
      5 hours ago










    • $begingroup$
      Wow! Would still be nice to understand the thought process, but that definitely answers the question.
      $endgroup$
      – barrycarter
      4 hours ago










    • $begingroup$
      Is there a copy error here? I''m not about to debug the jumble, but as is it blows up with a stream of errors under 12 and 11.3 MMA on my machine.
      $endgroup$
      – ciao
      4 hours ago










    • $begingroup$
      Read my comments to OP: I believe they have misinterpreted the OEIS entry, and generation is much simpler.
      $endgroup$
      – ciao
      3 hours ago















    1












    $begingroup$

    ...and we are done!

    Solution for k=44 in 10 seconds



    k=44;
    r=Last@Select[Flatten[Table[Select[Riffle[#,-Last@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2],Floor[(k-1)/2],b=Range[s=Floor[Floor[(Floor[k^2/2]-1)/2]/Floor[k/2]],s+2]]]&/@Reverse/@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2]+1,Ceiling[(k-1)/2],Range[s=Floor[Floor[(Floor[k^2/2] - 1)/2]/Floor[k/2]],s+k-8]],Union[FoldList[Total[##]&,p,#]]==Range@k&],p,k],1],Union@Differences@Union[FoldList[Total[##]&,#[[1]],#]]==1&];w=FoldList[Total[##]&,1,r];
    f=w+k-Max@w
    Total@Abs@Differences@f
    Floor[k^2/2]-1



    k=44



    22,44,21,43,20,42,19,41,18,40,17,39,16,38,15,37,14,36,13,35,12,34,11,33,10,32,9,31,8,30,7,29,6,28,5,27,4,26,3,25,2,24,1,23

    967

    967




    This algorithm tries to find the differences-list of the result.



    By examining the differences we can see that half of them are positive and half negative. Also sum of positives is equal to sum of negatives +1 and they are riffled.
    So we are trying to produce those two sets using IntegerPartition but we must choose as less results as possible in order for this to terminate. In order to make this work we have to "fine-tune" the variable c of the following algorithm
    (otherwise it will throw errors). The goal of this answer was to reach k=44 which seemed impossible by testing permutations...

    Here are the correct values in order to hit k=50



    k=50;
    c=15;
    r=Last@Select[Flatten[Table[Select[Riffle[#,-Last@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2],Floor[(k-1)/2],b=Range[s=Floor[Floor[(Floor[k^2/2]-1)/2]/Floor[k/2]],s+2]]]&/@Reverse/@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2]+1,Ceiling[(k-1)/2],Range[s=Floor[Floor[(Floor[k^2/2] - 1)/2]/Floor[k/2]],s+c]],Union[FoldList[Total[##]&,p,#]]==Range@k&],p,k],1],Union@Differences@Union[FoldList[Total[##]&,#[[1]],#]]==1&];w=FoldList[Total[##]&,1,r];
    f=w+k-Max@w
    Total@Abs@Differences@f
    Floor[k^2/2]-1



    k=50

    25,50,24,49,23,48,22,47,21,46,20,45,19,44,18,43,17,42,16,41,15,40,14,39,13,38,12,37,11,36,10,35,9,34,8,33,7,32,6,31,5,30,4,29,3,28,2,27,1,26

    1249

    1249







    share|improve this answer











    $endgroup$












    • $begingroup$
      Shiny! Any chance you could explain it? It looks like you don't user Permutations, but instead IntegerPartitions to find which integers add up to the magic number? And then what?
      $endgroup$
      – barrycarter
      5 hours ago










    • $begingroup$
      Actually I studied the differences and tried to produce differences that work. Right now I'm working on some modifications... I let you know
      $endgroup$
      – J42161217
      5 hours ago










    • $begingroup$
      Wow! Would still be nice to understand the thought process, but that definitely answers the question.
      $endgroup$
      – barrycarter
      4 hours ago










    • $begingroup$
      Is there a copy error here? I''m not about to debug the jumble, but as is it blows up with a stream of errors under 12 and 11.3 MMA on my machine.
      $endgroup$
      – ciao
      4 hours ago










    • $begingroup$
      Read my comments to OP: I believe they have misinterpreted the OEIS entry, and generation is much simpler.
      $endgroup$
      – ciao
      3 hours ago













    1












    1








    1





    $begingroup$

    ...and we are done!

    Solution for k=44 in 10 seconds



    k=44;
    r=Last@Select[Flatten[Table[Select[Riffle[#,-Last@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2],Floor[(k-1)/2],b=Range[s=Floor[Floor[(Floor[k^2/2]-1)/2]/Floor[k/2]],s+2]]]&/@Reverse/@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2]+1,Ceiling[(k-1)/2],Range[s=Floor[Floor[(Floor[k^2/2] - 1)/2]/Floor[k/2]],s+k-8]],Union[FoldList[Total[##]&,p,#]]==Range@k&],p,k],1],Union@Differences@Union[FoldList[Total[##]&,#[[1]],#]]==1&];w=FoldList[Total[##]&,1,r];
    f=w+k-Max@w
    Total@Abs@Differences@f
    Floor[k^2/2]-1



    k=44



    22,44,21,43,20,42,19,41,18,40,17,39,16,38,15,37,14,36,13,35,12,34,11,33,10,32,9,31,8,30,7,29,6,28,5,27,4,26,3,25,2,24,1,23

    967

    967




    This algorithm tries to find the differences-list of the result.



    By examining the differences we can see that half of them are positive and half negative. Also sum of positives is equal to sum of negatives +1 and they are riffled.
    So we are trying to produce those two sets using IntegerPartition but we must choose as less results as possible in order for this to terminate. In order to make this work we have to "fine-tune" the variable c of the following algorithm
    (otherwise it will throw errors). The goal of this answer was to reach k=44 which seemed impossible by testing permutations...

    Here are the correct values in order to hit k=50



    k=50;
    c=15;
    r=Last@Select[Flatten[Table[Select[Riffle[#,-Last@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2],Floor[(k-1)/2],b=Range[s=Floor[Floor[(Floor[k^2/2]-1)/2]/Floor[k/2]],s+2]]]&/@Reverse/@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2]+1,Ceiling[(k-1)/2],Range[s=Floor[Floor[(Floor[k^2/2] - 1)/2]/Floor[k/2]],s+c]],Union[FoldList[Total[##]&,p,#]]==Range@k&],p,k],1],Union@Differences@Union[FoldList[Total[##]&,#[[1]],#]]==1&];w=FoldList[Total[##]&,1,r];
    f=w+k-Max@w
    Total@Abs@Differences@f
    Floor[k^2/2]-1



    k=50

    25,50,24,49,23,48,22,47,21,46,20,45,19,44,18,43,17,42,16,41,15,40,14,39,13,38,12,37,11,36,10,35,9,34,8,33,7,32,6,31,5,30,4,29,3,28,2,27,1,26

    1249

    1249







    share|improve this answer











    $endgroup$



    ...and we are done!

    Solution for k=44 in 10 seconds



    k=44;
    r=Last@Select[Flatten[Table[Select[Riffle[#,-Last@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2],Floor[(k-1)/2],b=Range[s=Floor[Floor[(Floor[k^2/2]-1)/2]/Floor[k/2]],s+2]]]&/@Reverse/@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2]+1,Ceiling[(k-1)/2],Range[s=Floor[Floor[(Floor[k^2/2] - 1)/2]/Floor[k/2]],s+k-8]],Union[FoldList[Total[##]&,p,#]]==Range@k&],p,k],1],Union@Differences@Union[FoldList[Total[##]&,#[[1]],#]]==1&];w=FoldList[Total[##]&,1,r];
    f=w+k-Max@w
    Total@Abs@Differences@f
    Floor[k^2/2]-1



    k=44



    22,44,21,43,20,42,19,41,18,40,17,39,16,38,15,37,14,36,13,35,12,34,11,33,10,32,9,31,8,30,7,29,6,28,5,27,4,26,3,25,2,24,1,23

    967

    967




    This algorithm tries to find the differences-list of the result.



    By examining the differences we can see that half of them are positive and half negative. Also sum of positives is equal to sum of negatives +1 and they are riffled.
    So we are trying to produce those two sets using IntegerPartition but we must choose as less results as possible in order for this to terminate. In order to make this work we have to "fine-tune" the variable c of the following algorithm
    (otherwise it will throw errors). The goal of this answer was to reach k=44 which seemed impossible by testing permutations...

    Here are the correct values in order to hit k=50



    k=50;
    c=15;
    r=Last@Select[Flatten[Table[Select[Riffle[#,-Last@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2],Floor[(k-1)/2],b=Range[s=Floor[Floor[(Floor[k^2/2]-1)/2]/Floor[k/2]],s+2]]]&/@Reverse/@IntegerPartitions[Floor[(Floor[k^2/2]-1)/2]+1,Ceiling[(k-1)/2],Range[s=Floor[Floor[(Floor[k^2/2] - 1)/2]/Floor[k/2]],s+c]],Union[FoldList[Total[##]&,p,#]]==Range@k&],p,k],1],Union@Differences@Union[FoldList[Total[##]&,#[[1]],#]]==1&];w=FoldList[Total[##]&,1,r];
    f=w+k-Max@w
    Total@Abs@Differences@f
    Floor[k^2/2]-1



    k=50

    25,50,24,49,23,48,22,47,21,46,20,45,19,44,18,43,17,42,16,41,15,40,14,39,13,38,12,37,11,36,10,35,9,34,8,33,7,32,6,31,5,30,4,29,3,28,2,27,1,26

    1249

    1249








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 3 hours ago

























    answered 5 hours ago









    J42161217J42161217

    5,315525




    5,315525











    • $begingroup$
      Shiny! Any chance you could explain it? It looks like you don't user Permutations, but instead IntegerPartitions to find which integers add up to the magic number? And then what?
      $endgroup$
      – barrycarter
      5 hours ago










    • $begingroup$
      Actually I studied the differences and tried to produce differences that work. Right now I'm working on some modifications... I let you know
      $endgroup$
      – J42161217
      5 hours ago










    • $begingroup$
      Wow! Would still be nice to understand the thought process, but that definitely answers the question.
      $endgroup$
      – barrycarter
      4 hours ago










    • $begingroup$
      Is there a copy error here? I''m not about to debug the jumble, but as is it blows up with a stream of errors under 12 and 11.3 MMA on my machine.
      $endgroup$
      – ciao
      4 hours ago










    • $begingroup$
      Read my comments to OP: I believe they have misinterpreted the OEIS entry, and generation is much simpler.
      $endgroup$
      – ciao
      3 hours ago
















    • $begingroup$
      Shiny! Any chance you could explain it? It looks like you don't user Permutations, but instead IntegerPartitions to find which integers add up to the magic number? And then what?
      $endgroup$
      – barrycarter
      5 hours ago










    • $begingroup$
      Actually I studied the differences and tried to produce differences that work. Right now I'm working on some modifications... I let you know
      $endgroup$
      – J42161217
      5 hours ago










    • $begingroup$
      Wow! Would still be nice to understand the thought process, but that definitely answers the question.
      $endgroup$
      – barrycarter
      4 hours ago










    • $begingroup$
      Is there a copy error here? I''m not about to debug the jumble, but as is it blows up with a stream of errors under 12 and 11.3 MMA on my machine.
      $endgroup$
      – ciao
      4 hours ago










    • $begingroup$
      Read my comments to OP: I believe they have misinterpreted the OEIS entry, and generation is much simpler.
      $endgroup$
      – ciao
      3 hours ago















    $begingroup$
    Shiny! Any chance you could explain it? It looks like you don't user Permutations, but instead IntegerPartitions to find which integers add up to the magic number? And then what?
    $endgroup$
    – barrycarter
    5 hours ago




    $begingroup$
    Shiny! Any chance you could explain it? It looks like you don't user Permutations, but instead IntegerPartitions to find which integers add up to the magic number? And then what?
    $endgroup$
    – barrycarter
    5 hours ago












    $begingroup$
    Actually I studied the differences and tried to produce differences that work. Right now I'm working on some modifications... I let you know
    $endgroup$
    – J42161217
    5 hours ago




    $begingroup$
    Actually I studied the differences and tried to produce differences that work. Right now I'm working on some modifications... I let you know
    $endgroup$
    – J42161217
    5 hours ago












    $begingroup$
    Wow! Would still be nice to understand the thought process, but that definitely answers the question.
    $endgroup$
    – barrycarter
    4 hours ago




    $begingroup$
    Wow! Would still be nice to understand the thought process, but that definitely answers the question.
    $endgroup$
    – barrycarter
    4 hours ago












    $begingroup$
    Is there a copy error here? I''m not about to debug the jumble, but as is it blows up with a stream of errors under 12 and 11.3 MMA on my machine.
    $endgroup$
    – ciao
    4 hours ago




    $begingroup$
    Is there a copy error here? I''m not about to debug the jumble, but as is it blows up with a stream of errors under 12 and 11.3 MMA on my machine.
    $endgroup$
    – ciao
    4 hours ago












    $begingroup$
    Read my comments to OP: I believe they have misinterpreted the OEIS entry, and generation is much simpler.
    $endgroup$
    – ciao
    3 hours ago




    $begingroup$
    Read my comments to OP: I believe they have misinterpreted the OEIS entry, and generation is much simpler.
    $endgroup$
    – ciao
    3 hours ago











    4












    $begingroup$

    This answer just shows how to improve the speed of orgNumber:



    orgNumber2[p_] := Total @ Abs @ Differences @ p


    Comparison:



    t0 = Table[RandomSample[Range[44]],i,1,100000];

    t1 = Max[Map[orgNumber,t0]]; //AbsoluteTiming
    t2 = Max[Map[orgNumber2, t0]]; //AbsoluteTiming

    t1==t2



    6.94362, Null



    0.4978, Null



    True




    Another almost order of magnitude increase in speed can be obtained by writing a version that works with multiple lists:



    orgNumber3[p:__List] := Total[Abs @ Transpose @ Differences[Transpose@p], 2]


    Timing:



    t3 = Max @ orgNumber3[t0]; //AbsoluteTiming
    t1 == t2 == t3



    0.070115, Null



    True




    Addendum



    Using ciao's comment, producing the desired permutation is simple:



    maxPerm[n_] := Ordering @ Join[
    Range[2, 2 Floor[n/2], 2],
    1,
    Range[2 Ceiling[n/2] - 1, 3, -2]
    ]


    For $n=44$:



    r = maxPerm[44]; //AbsoluteTiming
    r
    orgNumber2[r]



    0.000045, Null



    23, 1, 44, 2, 43, 3, 42, 4, 41, 5, 40, 6, 39, 7, 38, 8, 37, 9, 36,
    10, 35, 11, 34, 12, 33, 13, 32, 14, 31, 15, 30, 16, 29, 17, 28, 18,
    27, 19, 26, 20, 25, 21, 24, 22



    967




    For $n = 10^6$ :



    n = 10^6;
    r = maxPerm[n]; //AbsoluteTiming
    orgNumber2[r]
    Floor[n^2/2] - 1



    0.019479, Null



    499999999999



    499999999999







    share|improve this answer











    $endgroup$

















      4












      $begingroup$

      This answer just shows how to improve the speed of orgNumber:



      orgNumber2[p_] := Total @ Abs @ Differences @ p


      Comparison:



      t0 = Table[RandomSample[Range[44]],i,1,100000];

      t1 = Max[Map[orgNumber,t0]]; //AbsoluteTiming
      t2 = Max[Map[orgNumber2, t0]]; //AbsoluteTiming

      t1==t2



      6.94362, Null



      0.4978, Null



      True




      Another almost order of magnitude increase in speed can be obtained by writing a version that works with multiple lists:



      orgNumber3[p:__List] := Total[Abs @ Transpose @ Differences[Transpose@p], 2]


      Timing:



      t3 = Max @ orgNumber3[t0]; //AbsoluteTiming
      t1 == t2 == t3



      0.070115, Null



      True




      Addendum



      Using ciao's comment, producing the desired permutation is simple:



      maxPerm[n_] := Ordering @ Join[
      Range[2, 2 Floor[n/2], 2],
      1,
      Range[2 Ceiling[n/2] - 1, 3, -2]
      ]


      For $n=44$:



      r = maxPerm[44]; //AbsoluteTiming
      r
      orgNumber2[r]



      0.000045, Null



      23, 1, 44, 2, 43, 3, 42, 4, 41, 5, 40, 6, 39, 7, 38, 8, 37, 9, 36,
      10, 35, 11, 34, 12, 33, 13, 32, 14, 31, 15, 30, 16, 29, 17, 28, 18,
      27, 19, 26, 20, 25, 21, 24, 22



      967




      For $n = 10^6$ :



      n = 10^6;
      r = maxPerm[n]; //AbsoluteTiming
      orgNumber2[r]
      Floor[n^2/2] - 1



      0.019479, Null



      499999999999



      499999999999







      share|improve this answer











      $endgroup$















        4












        4








        4





        $begingroup$

        This answer just shows how to improve the speed of orgNumber:



        orgNumber2[p_] := Total @ Abs @ Differences @ p


        Comparison:



        t0 = Table[RandomSample[Range[44]],i,1,100000];

        t1 = Max[Map[orgNumber,t0]]; //AbsoluteTiming
        t2 = Max[Map[orgNumber2, t0]]; //AbsoluteTiming

        t1==t2



        6.94362, Null



        0.4978, Null



        True




        Another almost order of magnitude increase in speed can be obtained by writing a version that works with multiple lists:



        orgNumber3[p:__List] := Total[Abs @ Transpose @ Differences[Transpose@p], 2]


        Timing:



        t3 = Max @ orgNumber3[t0]; //AbsoluteTiming
        t1 == t2 == t3



        0.070115, Null



        True




        Addendum



        Using ciao's comment, producing the desired permutation is simple:



        maxPerm[n_] := Ordering @ Join[
        Range[2, 2 Floor[n/2], 2],
        1,
        Range[2 Ceiling[n/2] - 1, 3, -2]
        ]


        For $n=44$:



        r = maxPerm[44]; //AbsoluteTiming
        r
        orgNumber2[r]



        0.000045, Null



        23, 1, 44, 2, 43, 3, 42, 4, 41, 5, 40, 6, 39, 7, 38, 8, 37, 9, 36,
        10, 35, 11, 34, 12, 33, 13, 32, 14, 31, 15, 30, 16, 29, 17, 28, 18,
        27, 19, 26, 20, 25, 21, 24, 22



        967




        For $n = 10^6$ :



        n = 10^6;
        r = maxPerm[n]; //AbsoluteTiming
        orgNumber2[r]
        Floor[n^2/2] - 1



        0.019479, Null



        499999999999



        499999999999







        share|improve this answer











        $endgroup$



        This answer just shows how to improve the speed of orgNumber:



        orgNumber2[p_] := Total @ Abs @ Differences @ p


        Comparison:



        t0 = Table[RandomSample[Range[44]],i,1,100000];

        t1 = Max[Map[orgNumber,t0]]; //AbsoluteTiming
        t2 = Max[Map[orgNumber2, t0]]; //AbsoluteTiming

        t1==t2



        6.94362, Null



        0.4978, Null



        True




        Another almost order of magnitude increase in speed can be obtained by writing a version that works with multiple lists:



        orgNumber3[p:__List] := Total[Abs @ Transpose @ Differences[Transpose@p], 2]


        Timing:



        t3 = Max @ orgNumber3[t0]; //AbsoluteTiming
        t1 == t2 == t3



        0.070115, Null



        True




        Addendum



        Using ciao's comment, producing the desired permutation is simple:



        maxPerm[n_] := Ordering @ Join[
        Range[2, 2 Floor[n/2], 2],
        1,
        Range[2 Ceiling[n/2] - 1, 3, -2]
        ]


        For $n=44$:



        r = maxPerm[44]; //AbsoluteTiming
        r
        orgNumber2[r]



        0.000045, Null



        23, 1, 44, 2, 43, 3, 42, 4, 41, 5, 40, 6, 39, 7, 38, 8, 37, 9, 36,
        10, 35, 11, 34, 12, 33, 13, 32, 14, 31, 15, 30, 16, 29, 17, 28, 18,
        27, 19, 26, 20, 25, 21, 24, 22



        967




        For $n = 10^6$ :



        n = 10^6;
        r = maxPerm[n]; //AbsoluteTiming
        orgNumber2[r]
        Floor[n^2/2] - 1



        0.019479, Null



        499999999999



        499999999999








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 3 hours ago

























        answered 7 hours ago









        Carl WollCarl Woll

        80.1k3102207




        80.1k3102207



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f198888%2ffind-permutation-with-highest-organization-number-oeis-a047838%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її