Python Forum
need help with solution-checker function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help with solution-checker function
#2
You could use a generator
def indexes():
    r = (0 ,1, 2)
    for i in r:
        yield [(i, j) for j in r]
        yield [(j, i) for j in r]
    yield [(i, i) for i in r]
    yield [(2-i, i) for i in r]
    
def won(grid):
    for r in indexes():
        a, b, c = [grid[i][j] for (i, j) in r]
        if a != '-' and a == b and b == c:
            return True
    return False
Reply


Messages In This Thread
RE: need help with solution-checker function - by Gribouillis - Jan-09-2018, 09:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  To put a solution of an equation into a function pianistseb 6 3,460 Nov-11-2018, 08:22 PM
Last Post: pianistseb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020