Post Reply 
Fifteen puzzle solvability, Numworks Python
04-09-2020, 04:30 PM
Post: #10
RE: Fifteen puzzle solvability, Numworks Python
(04-09-2020 03:23 PM)stored Wrote:  Oh, you are right again.
I was sloppy.
Code:
def fifteen(a):
  b = 0
  for i in range(16):
    if a[i] == 0:
      b = 1 + i // 4
  for i in range(15):
    for j in range(i+1, 16):
      b += (a[j] < a[i]) * (a[j] != 0)
  return b
Thanks, stored, looks like you did it! I tested with about a dozen examples I have in my files and they all worked.

And thanks for enlightening me in aspects of Python I was not familiar with. I am new to that language and you have helped me understand a lot about it.
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 04:30 PM



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