#!/bin/python3 import sys,re,math from pprint import pprint input_f = 'input' part = 2 def manhattan(a, b): return int(sum(abs(val1-val2) for val1, val2 in zip(a,b))/2) ######################################### # # # Part 1 # # # ######################################### # https://www.redblobgames.com/grids/hexagons/ if part == 1: with open(input_f) as file: for line in file: steps = line.rsplit()[0].split(',') #print(steps) grid = [] w, h = 11,11 grid = [[' ' for x in range(w)] for y in range(h)] start = int(len(grid)/2) distance = [] x = 0 y = 0 z = 0 for i in steps: if i == 'ne': x += 1 z -= 1 if i == 'sw': x -= 1 z += 1 if i == 's': z += 1 y -= 1 if i == 'n': z -= 1 y += 1 if i == 'se': x += 1 y -= 1 if i == 'nw': x -= 1 y += 1 print(int((abs(x)+abs(y)+abs(z))/2)) ######################################### # # # Part 2 # # # ######################################### if part == 2: with open(input_f) as file: for line in file: steps = line.rsplit()[0].split(',') distance = [] x = 0 y = 0 z = 0 for i in steps: if i == 'ne': x += 1 z -= 1 if i == 'sw': x -= 1 z += 1 if i == 's': z += 1 y -= 1 if i == 'n': z -= 1 y += 1 if i == 'se': x += 1 y -= 1 if i == 'nw': x -= 1 y += 1 distance.append((abs(x)+abs(y)+abs(z))/2) print('Distance:',int(max(distance)))