Skip to content

Instantly share code, notes, and snippets.

@SnowyPainter
Created May 4, 2021 16:51
Show Gist options
  • Save SnowyPainter/573127d96f3921a0e819265ec7ee2f5b to your computer and use it in GitHub Desktop.
Save SnowyPainter/573127d96f3921a0e819265ec7ee2f5b to your computer and use it in GitHub Desktop.
빙고게임 채점 알고리즘
def all_same(arr):
temp = arr[0]
for v in arr[1:]:
if temp == v:
temp = v
else:
return False
return True
def the_highest_value_key(dictionary):
highest = 0
highest_key = ""
for k, v in dictionary.items():
if v > highest:
highest = v
highest_key = k
return highest_key
def bingo_winner(markers,squre_input, l):
players_score = {}
for p in markers:
players_score[p] = 0
a = 0
b = l-1
c1 = []
c2 = []
#row
for i in range (0,l*l, l):
v = squre_input[i:i+l]
if all_same(v):
players_score[v[0]] += 1
c1.append(v[a])
c2.append(v[b])
a += 1
b -= 1
#column
for j in range(0, l):
v = []
for k in range(0, l):
v.append(squre_input[l*k + j])
if all_same(v):
players_score[v[0]] += 1
if all_same(c1):
players_score[c1[0]] += 1
if all_same(c2):
players_score[c2[0]] += 1
return the_highest_value_key(players_score)
input = [1,0,1,
1,1,1,
0,1,1]
print("The Bingo winner is {}".format(bingo_winner([1,0],input,3)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment