advent-of-code

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 42a79ad9b3b87b2903508c31c34520d0bf5b8ab9
parent 63e4506e024a007965fa7ed7cfa3a07a098ed3fd
Author: mpizzzle <michael.770211@gmail.com>
Date:   Fri, 15 Dec 2017 02:14:28 +0000

puzzle 14 complete (needs a lot of refactoring)

Diffstat:
Mpuzzle14.py | 32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/puzzle14.py b/puzzle14.py @@ -26,3 +26,35 @@ def knot_hash(this_input): disk = [knot_hash([ord(c) for c in "amgozmfv-" + str(i)]) for i in range(128)] print sum([binary_hash[c] for c in "".join(disk)]) + +binary_disk = ["".join(["".join([str(int(int(c, 16) & 2**i > 0)) for i in reversed(range(4))]) for c in row]) for row in disk] +disk_hash = {} +network = [] + +print binary_disk + +for x in range(128): + for y in range(128): + disk_hash[str(x) + ',' + str(y)] = int(binary_disk[x][y]) + +def traverse(node): + network.append(node) + x_y = [int(n) for n in node.split(',')] + neighbours = [str(x_y[0]) + ',' + str(x_y[1] - 1), str(x_y[0]) + ',' + str(x_y[1] + 1), str(x_y[0] - 1) + ',' + str(x_y[1]), str(x_y[0] + 1) + ',' + str(x_y[1])] + for neighbour in neighbours: + if neighbour not in network: + if neighbour in disk_hash: + if disk_hash[neighbour]: + traverse(neighbour) + +size_of_network = 0 +network_count = 0 + +for node in disk_hash.keys(): + if disk_hash[node] and node not in network: + traverse(node) + if len(network) > size_of_network: + size_of_network = len(network) + network_count += 1 + +print network_count