Don't understand results obtained using itertools.permutations()How to return multiple values from a function?Understanding slice notationUnderstanding Python super() with __init__() methodsWhy does Python's itertools.permutations contain duplicates? (When the original list has duplicates)What is the difference between dict.items() and dict.iteritems()?Relative imports for the billionth time“Large data” work flows using pandasHow can I see normal print output created during pytest run?Difference between numpy.array shape (R, 1) and (R,)Understanding the PBBS Adjacency Graph format.
Multiplicative persistence
C++ check if statement can be evaluated constexpr
A Trivial Diagnosis
Is this toilet slogan correct usage of the English language?
Can I turn my anal-retentiveness into a career?
What does "Scientists rise up against statistical significance" mean? (Comment in Nature)
"It doesn't matter" or "it won't matter"?
What is going on with gets(stdin) on the site coderbyte?
When were female captains banned from Starfleet?
Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?
How much of a Devil Fruit must be consumed to gain the power?
Is there a RAID 0 Equivalent for RAM?
How can I write humor as character trait?
Can you use Vicious Mockery to win an argument or gain favours?
What is the English pronunciation of "pain au chocolat"?
Taxes on Dividends in a Roth IRA
Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?
Why is the Sun approximated as a black body at ~ 5800 K?
How can ping know if my host is down
What fields between the rationals and the reals allow a good notion of 2D distance?
C++ copy constructor called at return
Quoting Keynes in a lecture
Permission on Database
Does the Linux kernel need a file system to run?
Don't understand results obtained using itertools.permutations()
How to return multiple values from a function?Understanding slice notationUnderstanding Python super() with __init__() methodsWhy does Python's itertools.permutations contain duplicates? (When the original list has duplicates)What is the difference between dict.items() and dict.iteritems()?Relative imports for the billionth time“Large data” work flows using pandasHow can I see normal print output created during pytest run?Difference between numpy.array shape (R, 1) and (R,)Understanding the PBBS Adjacency Graph format.
This is the code to represent a set of distinct numbers from 0 to 15 in 12 space such that the differences between some adjacent numbers are also distinct.
import itertools
list = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
for i in itertools.permutations(list,12):
a1 = abs(i[0] - i[1])
b1 = abs(i[0] - i[2])
a = abs(i[0] - i[3])
b = abs(i[0] - i[4])
c = abs(i[0] - i[5])
d = abs(i[1] - i[6])
e = abs(i[2] - i[7])
f = abs(i[3] - i[8])
g = abs(i[4] - i[9])
h = abs(i[5] - i[10])
g1 = abs(i[6] - i[11])
h1 = abs(i[7] - i[11])
c1 = abs(i[8] - i[11])
d1 = abs(i[9] - i[11])
e1 = abs(i[10] - i[11])
L= [a1, b1, a, b, c, d, e, f, g, h, g1, h1, c1, d1, e1]
if (len(set(L))==15):
print(i)
print(L)
There seems to be no output for this code but I can't figure out why.
python permutation graph-theory
|
show 13 more comments
This is the code to represent a set of distinct numbers from 0 to 15 in 12 space such that the differences between some adjacent numbers are also distinct.
import itertools
list = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
for i in itertools.permutations(list,12):
a1 = abs(i[0] - i[1])
b1 = abs(i[0] - i[2])
a = abs(i[0] - i[3])
b = abs(i[0] - i[4])
c = abs(i[0] - i[5])
d = abs(i[1] - i[6])
e = abs(i[2] - i[7])
f = abs(i[3] - i[8])
g = abs(i[4] - i[9])
h = abs(i[5] - i[10])
g1 = abs(i[6] - i[11])
h1 = abs(i[7] - i[11])
c1 = abs(i[8] - i[11])
d1 = abs(i[9] - i[11])
e1 = abs(i[10] - i[11])
L= [a1, b1, a, b, c, d, e, f, g, h, g1, h1, c1, d1, e1]
if (len(set(L))==15):
print(i)
print(L)
There seems to be no output for this code but I can't figure out why.
python permutation graph-theory
1
Reword your question, not possible to understand what your code is supposed to do, maybe show the expected output.
– anand_v.singh
Mar 7 at 4:54
There are billions of such permutations. How are you sure that it is feasible to brute force it in Python?
– John Coleman
Mar 7 at 4:59
I'm having a hard time proving it, but I feel like you're running up against the pigeon hole principle regarding assigning[0, 16)
absolute differences uniquely to your pairs.
– Dillon Davis
Mar 7 at 5:00
1
Have you made any attempt at debugging this yourself? Printing out the largest value oflen(set(L))
seen so far might be instructive, to see if you're even getting close to 15 distinct differences.
– jasonharper
Mar 7 at 5:02
1
You just didn't wait long enough. I let your code run overnight, and had 3954 solutions printed out this morning (and it's still running!). First one was(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
, with differences[1, 3, 13, 14, 15, 9, 4, 7, 12, 11, 2, 5, 6, 10, 8]
.
– jasonharper
Mar 7 at 13:30
|
show 13 more comments
This is the code to represent a set of distinct numbers from 0 to 15 in 12 space such that the differences between some adjacent numbers are also distinct.
import itertools
list = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
for i in itertools.permutations(list,12):
a1 = abs(i[0] - i[1])
b1 = abs(i[0] - i[2])
a = abs(i[0] - i[3])
b = abs(i[0] - i[4])
c = abs(i[0] - i[5])
d = abs(i[1] - i[6])
e = abs(i[2] - i[7])
f = abs(i[3] - i[8])
g = abs(i[4] - i[9])
h = abs(i[5] - i[10])
g1 = abs(i[6] - i[11])
h1 = abs(i[7] - i[11])
c1 = abs(i[8] - i[11])
d1 = abs(i[9] - i[11])
e1 = abs(i[10] - i[11])
L= [a1, b1, a, b, c, d, e, f, g, h, g1, h1, c1, d1, e1]
if (len(set(L))==15):
print(i)
print(L)
There seems to be no output for this code but I can't figure out why.
python permutation graph-theory
This is the code to represent a set of distinct numbers from 0 to 15 in 12 space such that the differences between some adjacent numbers are also distinct.
import itertools
list = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
for i in itertools.permutations(list,12):
a1 = abs(i[0] - i[1])
b1 = abs(i[0] - i[2])
a = abs(i[0] - i[3])
b = abs(i[0] - i[4])
c = abs(i[0] - i[5])
d = abs(i[1] - i[6])
e = abs(i[2] - i[7])
f = abs(i[3] - i[8])
g = abs(i[4] - i[9])
h = abs(i[5] - i[10])
g1 = abs(i[6] - i[11])
h1 = abs(i[7] - i[11])
c1 = abs(i[8] - i[11])
d1 = abs(i[9] - i[11])
e1 = abs(i[10] - i[11])
L= [a1, b1, a, b, c, d, e, f, g, h, g1, h1, c1, d1, e1]
if (len(set(L))==15):
print(i)
print(L)
There seems to be no output for this code but I can't figure out why.
python permutation graph-theory
python permutation graph-theory
edited Mar 7 at 6:45
martineau
69.3k1092186
69.3k1092186
asked Mar 7 at 4:49
paritosh joshiparitosh joshi
61
61
1
Reword your question, not possible to understand what your code is supposed to do, maybe show the expected output.
– anand_v.singh
Mar 7 at 4:54
There are billions of such permutations. How are you sure that it is feasible to brute force it in Python?
– John Coleman
Mar 7 at 4:59
I'm having a hard time proving it, but I feel like you're running up against the pigeon hole principle regarding assigning[0, 16)
absolute differences uniquely to your pairs.
– Dillon Davis
Mar 7 at 5:00
1
Have you made any attempt at debugging this yourself? Printing out the largest value oflen(set(L))
seen so far might be instructive, to see if you're even getting close to 15 distinct differences.
– jasonharper
Mar 7 at 5:02
1
You just didn't wait long enough. I let your code run overnight, and had 3954 solutions printed out this morning (and it's still running!). First one was(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
, with differences[1, 3, 13, 14, 15, 9, 4, 7, 12, 11, 2, 5, 6, 10, 8]
.
– jasonharper
Mar 7 at 13:30
|
show 13 more comments
1
Reword your question, not possible to understand what your code is supposed to do, maybe show the expected output.
– anand_v.singh
Mar 7 at 4:54
There are billions of such permutations. How are you sure that it is feasible to brute force it in Python?
– John Coleman
Mar 7 at 4:59
I'm having a hard time proving it, but I feel like you're running up against the pigeon hole principle regarding assigning[0, 16)
absolute differences uniquely to your pairs.
– Dillon Davis
Mar 7 at 5:00
1
Have you made any attempt at debugging this yourself? Printing out the largest value oflen(set(L))
seen so far might be instructive, to see if you're even getting close to 15 distinct differences.
– jasonharper
Mar 7 at 5:02
1
You just didn't wait long enough. I let your code run overnight, and had 3954 solutions printed out this morning (and it's still running!). First one was(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
, with differences[1, 3, 13, 14, 15, 9, 4, 7, 12, 11, 2, 5, 6, 10, 8]
.
– jasonharper
Mar 7 at 13:30
1
1
Reword your question, not possible to understand what your code is supposed to do, maybe show the expected output.
– anand_v.singh
Mar 7 at 4:54
Reword your question, not possible to understand what your code is supposed to do, maybe show the expected output.
– anand_v.singh
Mar 7 at 4:54
There are billions of such permutations. How are you sure that it is feasible to brute force it in Python?
– John Coleman
Mar 7 at 4:59
There are billions of such permutations. How are you sure that it is feasible to brute force it in Python?
– John Coleman
Mar 7 at 4:59
I'm having a hard time proving it, but I feel like you're running up against the pigeon hole principle regarding assigning
[0, 16)
absolute differences uniquely to your pairs.– Dillon Davis
Mar 7 at 5:00
I'm having a hard time proving it, but I feel like you're running up against the pigeon hole principle regarding assigning
[0, 16)
absolute differences uniquely to your pairs.– Dillon Davis
Mar 7 at 5:00
1
1
Have you made any attempt at debugging this yourself? Printing out the largest value of
len(set(L))
seen so far might be instructive, to see if you're even getting close to 15 distinct differences.– jasonharper
Mar 7 at 5:02
Have you made any attempt at debugging this yourself? Printing out the largest value of
len(set(L))
seen so far might be instructive, to see if you're even getting close to 15 distinct differences.– jasonharper
Mar 7 at 5:02
1
1
You just didn't wait long enough. I let your code run overnight, and had 3954 solutions printed out this morning (and it's still running!). First one was
(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
, with differences [1, 3, 13, 14, 15, 9, 4, 7, 12, 11, 2, 5, 6, 10, 8]
.– jasonharper
Mar 7 at 13:30
You just didn't wait long enough. I let your code run overnight, and had 3954 solutions printed out this morning (and it's still running!). First one was
(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
, with differences [1, 3, 13, 14, 15, 9, 4, 7, 12, 11, 2, 5, 6, 10, 8]
.– jasonharper
Mar 7 at 13:30
|
show 13 more comments
1 Answer
1
active
oldest
votes
Here is an approach which generates random solutions. It moves all the variable checks into a loop and short-circuits the loop when there is a clash:
import itertools, random
labels = list(range(16))
edges = ((0,1),(0,2),(0,3),(0,4),(0,5),(1,6),(2,7),(3,8),(4,9),(5,10),(6,11),(7,11),(8,11),(9,11),(10,11))
num_vertices = 12
def solve(labels,edges,num_vertices):
shuffled_labels = labels[:] #make a copy
random.shuffle(shuffled_labels)
for p in itertools.permutations(shuffled_labels,num_vertices):
differences = [0]*16
solved = True #innocent until proven guilty
for i,j in edges:
difference = abs(p[i]-p[j])
differences[difference] += 1
if differences[difference] == 2:
solved = False
break #no need to check more edges
if solved:
return p
One run (of about 1 minute):
>>> solve(labels,edges,num_vertices)
(6, 5, 1, 14, 3, 2, 11, 15, 12, 13, 9, 0)
This is easily verified to satisfy your constraints.
Here is a generator solution which will yield all possible solutions:
def solutions(labels,edges,num_vertices):
for p in itertools.permutations(labels,num_vertices):
differences = [0]*16
solved = True #innocent until proven guilty
for i,j in edges:
difference = abs(p[i]-p[j])
differences[difference] += 1
if differences[difference] == 2:
solved = False
break #no need to check more edges
if solved:
yield p
Used like e.g.:
for p in solutions(labels,edges,num_vertices): print(p)
Unlike the random approach which usually returns in less than a minute, the generator churns away for a very long time before it starts yielding results. This suggests that the identity permutation (where this generator starts) is far from being a solution. Still, it does eventually yield permutations (after about 10-15 minutes), with the first one being:
(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
(agreeing with the result of @jasonharper).
Thank you very much.
– paritosh joshi
Mar 7 at 17:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036289%2fdont-understand-results-obtained-using-itertools-permutations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is an approach which generates random solutions. It moves all the variable checks into a loop and short-circuits the loop when there is a clash:
import itertools, random
labels = list(range(16))
edges = ((0,1),(0,2),(0,3),(0,4),(0,5),(1,6),(2,7),(3,8),(4,9),(5,10),(6,11),(7,11),(8,11),(9,11),(10,11))
num_vertices = 12
def solve(labels,edges,num_vertices):
shuffled_labels = labels[:] #make a copy
random.shuffle(shuffled_labels)
for p in itertools.permutations(shuffled_labels,num_vertices):
differences = [0]*16
solved = True #innocent until proven guilty
for i,j in edges:
difference = abs(p[i]-p[j])
differences[difference] += 1
if differences[difference] == 2:
solved = False
break #no need to check more edges
if solved:
return p
One run (of about 1 minute):
>>> solve(labels,edges,num_vertices)
(6, 5, 1, 14, 3, 2, 11, 15, 12, 13, 9, 0)
This is easily verified to satisfy your constraints.
Here is a generator solution which will yield all possible solutions:
def solutions(labels,edges,num_vertices):
for p in itertools.permutations(labels,num_vertices):
differences = [0]*16
solved = True #innocent until proven guilty
for i,j in edges:
difference = abs(p[i]-p[j])
differences[difference] += 1
if differences[difference] == 2:
solved = False
break #no need to check more edges
if solved:
yield p
Used like e.g.:
for p in solutions(labels,edges,num_vertices): print(p)
Unlike the random approach which usually returns in less than a minute, the generator churns away for a very long time before it starts yielding results. This suggests that the identity permutation (where this generator starts) is far from being a solution. Still, it does eventually yield permutations (after about 10-15 minutes), with the first one being:
(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
(agreeing with the result of @jasonharper).
Thank you very much.
– paritosh joshi
Mar 7 at 17:48
add a comment |
Here is an approach which generates random solutions. It moves all the variable checks into a loop and short-circuits the loop when there is a clash:
import itertools, random
labels = list(range(16))
edges = ((0,1),(0,2),(0,3),(0,4),(0,5),(1,6),(2,7),(3,8),(4,9),(5,10),(6,11),(7,11),(8,11),(9,11),(10,11))
num_vertices = 12
def solve(labels,edges,num_vertices):
shuffled_labels = labels[:] #make a copy
random.shuffle(shuffled_labels)
for p in itertools.permutations(shuffled_labels,num_vertices):
differences = [0]*16
solved = True #innocent until proven guilty
for i,j in edges:
difference = abs(p[i]-p[j])
differences[difference] += 1
if differences[difference] == 2:
solved = False
break #no need to check more edges
if solved:
return p
One run (of about 1 minute):
>>> solve(labels,edges,num_vertices)
(6, 5, 1, 14, 3, 2, 11, 15, 12, 13, 9, 0)
This is easily verified to satisfy your constraints.
Here is a generator solution which will yield all possible solutions:
def solutions(labels,edges,num_vertices):
for p in itertools.permutations(labels,num_vertices):
differences = [0]*16
solved = True #innocent until proven guilty
for i,j in edges:
difference = abs(p[i]-p[j])
differences[difference] += 1
if differences[difference] == 2:
solved = False
break #no need to check more edges
if solved:
yield p
Used like e.g.:
for p in solutions(labels,edges,num_vertices): print(p)
Unlike the random approach which usually returns in less than a minute, the generator churns away for a very long time before it starts yielding results. This suggests that the identity permutation (where this generator starts) is far from being a solution. Still, it does eventually yield permutations (after about 10-15 minutes), with the first one being:
(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
(agreeing with the result of @jasonharper).
Thank you very much.
– paritosh joshi
Mar 7 at 17:48
add a comment |
Here is an approach which generates random solutions. It moves all the variable checks into a loop and short-circuits the loop when there is a clash:
import itertools, random
labels = list(range(16))
edges = ((0,1),(0,2),(0,3),(0,4),(0,5),(1,6),(2,7),(3,8),(4,9),(5,10),(6,11),(7,11),(8,11),(9,11),(10,11))
num_vertices = 12
def solve(labels,edges,num_vertices):
shuffled_labels = labels[:] #make a copy
random.shuffle(shuffled_labels)
for p in itertools.permutations(shuffled_labels,num_vertices):
differences = [0]*16
solved = True #innocent until proven guilty
for i,j in edges:
difference = abs(p[i]-p[j])
differences[difference] += 1
if differences[difference] == 2:
solved = False
break #no need to check more edges
if solved:
return p
One run (of about 1 minute):
>>> solve(labels,edges,num_vertices)
(6, 5, 1, 14, 3, 2, 11, 15, 12, 13, 9, 0)
This is easily verified to satisfy your constraints.
Here is a generator solution which will yield all possible solutions:
def solutions(labels,edges,num_vertices):
for p in itertools.permutations(labels,num_vertices):
differences = [0]*16
solved = True #innocent until proven guilty
for i,j in edges:
difference = abs(p[i]-p[j])
differences[difference] += 1
if differences[difference] == 2:
solved = False
break #no need to check more edges
if solved:
yield p
Used like e.g.:
for p in solutions(labels,edges,num_vertices): print(p)
Unlike the random approach which usually returns in less than a minute, the generator churns away for a very long time before it starts yielding results. This suggests that the identity permutation (where this generator starts) is far from being a solution. Still, it does eventually yield permutations (after about 10-15 minutes), with the first one being:
(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
(agreeing with the result of @jasonharper).
Here is an approach which generates random solutions. It moves all the variable checks into a loop and short-circuits the loop when there is a clash:
import itertools, random
labels = list(range(16))
edges = ((0,1),(0,2),(0,3),(0,4),(0,5),(1,6),(2,7),(3,8),(4,9),(5,10),(6,11),(7,11),(8,11),(9,11),(10,11))
num_vertices = 12
def solve(labels,edges,num_vertices):
shuffled_labels = labels[:] #make a copy
random.shuffle(shuffled_labels)
for p in itertools.permutations(shuffled_labels,num_vertices):
differences = [0]*16
solved = True #innocent until proven guilty
for i,j in edges:
difference = abs(p[i]-p[j])
differences[difference] += 1
if differences[difference] == 2:
solved = False
break #no need to check more edges
if solved:
return p
One run (of about 1 minute):
>>> solve(labels,edges,num_vertices)
(6, 5, 1, 14, 3, 2, 11, 15, 12, 13, 9, 0)
This is easily verified to satisfy your constraints.
Here is a generator solution which will yield all possible solutions:
def solutions(labels,edges,num_vertices):
for p in itertools.permutations(labels,num_vertices):
differences = [0]*16
solved = True #innocent until proven guilty
for i,j in edges:
difference = abs(p[i]-p[j])
differences[difference] += 1
if differences[difference] == 2:
solved = False
break #no need to check more edges
if solved:
yield p
Used like e.g.:
for p in solutions(labels,edges,num_vertices): print(p)
Unlike the random approach which usually returns in less than a minute, the generator churns away for a very long time before it starts yielding results. This suggests that the identity permutation (where this generator starts) is far from being a solution. Still, it does eventually yield permutations (after about 10-15 minutes), with the first one being:
(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
(agreeing with the result of @jasonharper).
edited Mar 7 at 18:20
answered Mar 7 at 16:33
John ColemanJohn Coleman
35.5k53477
35.5k53477
Thank you very much.
– paritosh joshi
Mar 7 at 17:48
add a comment |
Thank you very much.
– paritosh joshi
Mar 7 at 17:48
Thank you very much.
– paritosh joshi
Mar 7 at 17:48
Thank you very much.
– paritosh joshi
Mar 7 at 17:48
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036289%2fdont-understand-results-obtained-using-itertools-permutations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Reword your question, not possible to understand what your code is supposed to do, maybe show the expected output.
– anand_v.singh
Mar 7 at 4:54
There are billions of such permutations. How are you sure that it is feasible to brute force it in Python?
– John Coleman
Mar 7 at 4:59
I'm having a hard time proving it, but I feel like you're running up against the pigeon hole principle regarding assigning
[0, 16)
absolute differences uniquely to your pairs.– Dillon Davis
Mar 7 at 5:00
1
Have you made any attempt at debugging this yourself? Printing out the largest value of
len(set(L))
seen so far might be instructive, to see if you're even getting close to 15 distinct differences.– jasonharper
Mar 7 at 5:02
1
You just didn't wait long enough. I let your code run overnight, and had 3954 solutions printed out this morning (and it's still running!). First one was
(0, 1, 3, 13, 14, 15, 10, 7, 6, 2, 4, 12)
, with differences[1, 3, 13, 14, 15, 9, 4, 7, 12, 11, 2, 5, 6, 10, 8]
.– jasonharper
Mar 7 at 13:30