Created
November 8, 2017 01:21
-
-
Save ashlynnpai/10d2d1eca3d50831d605760c8b8ed0a4 to your computer and use it in GitHub Desktop.
This file contains 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
#Code Wars kata solution | |
def damaged_or_sunk (board, attacks): | |
hits = [] | |
results = { 'sunk': 0, 'damaged': 0 , 'not_touched': 0, 'points': 0} | |
for attack in attacks: | |
x = attack[0]-1 | |
y = len(board)-attack[1] | |
if board[y][x] != 0: | |
hits.append(board[y][x]) | |
board[y][x] = "X" | |
hits = set(hits) | |
print hits | |
for num in range(1,4): | |
if num in [j for i in board for j in i]: | |
if num in hits: | |
results['damaged'] += 1 | |
else: | |
results['not_touched'] += 1 | |
if num not in [j for i in board for j in i] and num in hits: | |
results['sunk'] += 1 | |
print "+1" | |
results['points'] = 1*results['sunk'] + 0.5 * results['damaged'] + (-1)*results['not_touched'] | |
board = [[0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0]] | |
attacks = [[3, 1], [3, 2], [3, 3]] | |
damaged_or_sunk (board, attacks) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment