Created
September 9, 2019 19:09
-
-
Save aambrioso1/a972b9bb591b3d1881dc0f1798e8bb1c to your computer and use it in GitHub Desktop.
tictactoe.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
row_list = ['AAA', 'BBB', 'AAA'] | |
bd = row_list[0] + row_list[1] + row_list[2] | |
""" | |
# List matrix for board | |
board = [[],[],[]] | |
i = 0 | |
row_list = ['abc', 'cde','fgh'] | |
board2 = 'abbaccdee' | |
bd = 'COWXXOABC' | |
for s in row_list: | |
for c in s: | |
board[i].append(c) | |
i += 1 | |
""" | |
""" | |
def print_row(row_list, n): | |
return row_list[n-1] | |
def print_column(row_list,n): | |
col = '' | |
for i in range(3): | |
col += row_list[i][n-1] | |
return col | |
def print_down_diag(row_list): | |
diag = '' | |
for i in range(3): | |
d_diag += row_list[i][i] | |
return diag | |
def print_up_diag(row_list): | |
u_diag = '' | |
for i in range(3): | |
diag += row_list[2-i][i] | |
return diag | |
def pick_three(s,i,j,k): | |
return [s[i-1], s[j-1],s[k-1]] | |
""" | |
# Define strings for the rows, colums and | |
# that must be checked. | |
row1 = bd[:3] | |
row2 = bd[3:6] | |
row3 = bd[6:] | |
col1 = '' + bd[0] + bd[3] + bd[6] | |
col2 = '' + bd[1] + bd[4] + bd[7] | |
col3 = '' + bd[2] + bd[5] + bd[8] | |
diag1 = '' + bd[0] + bd[4] + bd[8] | |
diag2 = '' + bd[2] + bd[4] + bd[6] | |
# Create a list of rows to check to use for iteration. | |
checklist = [row1, row2, row3, col1, col2, col3, diag1, diag2] | |
""" | |
print(checklist) | |
j=0 | |
L =[] | |
for i in alphabet: | |
j += 1 | |
L.append(pick_three(board2,7,8,9).count(i)) | |
print(L) | |
print(L.count(1), L.count(2)) | |
""" | |
# Create the subsets of checklist that are wins for one monkey (singlewinnerlist) or two monkeys (double winnerlist). | |
countlist = [] | |
singlewinner = [] | |
doublewinner = [] | |
for s in checklist: | |
for char in alphabet: | |
countlist.append(s.count(char)) | |
if s.count(char) == 3: | |
singlewinner.append(s) | |
if s.count(char) == 2: | |
doublewinner.append(s) | |
#print(countlist) | |
print('singlewinner: ', singlewinner) | |
print('doublewinner: ', doublewinner) | |
# print(countlist.count(2), countlist.count(3)) | |
# Create a list of the monkeys that have a win on their own (singlewinnerlist) or with a partner (doublewinnerlist). Note that it is important count single monkeys and teams not wims! | |
singlewinnerlist = [] | |
doublewinnerlist = [] | |
for i in singlewinner: | |
k = set(i) | |
singlewinnerlist.append(k) | |
for i in doublewinner: | |
k = set(i) | |
if k not in doublewinnerlist: | |
doublewinnerlist.append(k) | |
doublewinnerlist | |
print('winnerlists ', singlewinnerlist, doublewinnerlist) | |
print('\nThe solution is:') | |
print(len(singlewinnerlist)) | |
print(len(doublewinnerlist)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment