Post Reply 
Fifteen puzzle solvability, Numworks Python
04-09-2020, 12:13 PM
Post: #4
RE: Fifteen puzzle solvability, Numworks Python
(04-09-2020 08:32 AM)stored Wrote:  Without "99" you can get a bit simpler code:
Code:

def fifteen(a):
  b = 0
  for i in range(15):
    for j in range(i+1, 16):
      b += a[j] < a[i]
  return b


a = [11,0,3,8,1,6,15,10,7,14,2,13,4,12,9,5]
print(fifteen(a))  # 52
This works for the data you showed, but it does not work with this data:
[15,9,2,14,4,6,0,8,11,1,13,3,7,12,5,10]

that data should return 58, but it returns 62
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Fifteen puzzle solvability, Numworks Python - Don Shepherd - 04-09-2020 12:13 PM



User(s) browsing this thread: 1 Guest(s)