Post Reply 
Fifteen puzzle solvability, Numworks Python
04-09-2020, 08:32 AM (This post was last modified: 04-09-2020 08:40 AM by stored.)
Post: #3
RE: Fifteen puzzle solvability, Numworks Python
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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Fifteen puzzle solvability, Numworks Python - stored - 04-09-2020 08:32 AM



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