import os import re import common.util as u #import common.comp as c import logging data = u.readfile(u.AOC_2020 + "\\11\\input.txt") #print(data) def count(data): empty= 0 occupied = 0 floor = 0 for r in data: for c in r: if c == 'L': empty+=1 elif c == '#': occupied+=1 elif c == ".": floor+=1 return (empty, occupied, floor, empty+occupied+floor) #return true if a seat is occupied def status1(data,r,c): if data[r][c] == '.': return '.' count = 0 for i in range(r-1,r+2): for j in range(c-1,c+2):
#print(os.getcwd()) def pp(a): for row in range(len(a)): for col in range(len(a[row])): if a[row, col] == 0: print('.', end='') else: print('#', end='') print("") print("") if __name__ == "__main__": data = u.readfile(u.AOC_2021 + "\\14\\input_test.txt", Integer=False) rules = {} pt = data[0] for i in range(2, len(data)): r = data[i].split(' ') k = r[0] v = r[-1] rules[k] = v print(rules) d = deque() for p in pt: d.append(p) i = 0
import os import re import common.util as u import numpy as np #print(os.getcwd()) data = u.readfile(u.AOC_2021 + "\\9\\input.txt", Integer=False) ROW = len(data) COL = len(data[0]) # Initialize direction vectors dRow = [0, 1, 0, -1] dCol = [-1, 0, 1, 0] vis = [[False for i in range(COL)] for j in range(ROW)] # Function to check if mat[row][col] # is unvisited and lies within the # boundary of the given matrix def isValid(row, col): global ROW global COL global vis # If cell is out of bounds if (row < 0 or col < 0 or row >= ROW or col >= COL): return False # If the cell is already visited if (vis[row][col]):
import os import re import common.util as u #print(os.getcwd()) lines = u.readfile(u.AOC_2021 + "\\5\\input.txt",Integer=False) class Table: W = 5 H = 5 def __init__(self,x,y): self.x = x self.y = y self.table = [ [0]*x for i in range(y)] self.points = [] # self.table[0][0] = 1 # self.table[9][9] = 3 # self.table[0][9] = 2 # self.table[9][0] = 4 def print(self): for y in range(self.y): print(self.table[y]) def addLine(self,x1,y1,x2,y2): self.points.append([x1,y1,x2,y2]) if y1 == y2: if x1 < x2: # horiz
#print(os.getcwd()) def pp(a): for row in range(len(a)): for col in range(len(a[row])): if a[row, col] == 0: print('.', end='') else: print('#', end='') print("") print("") if __name__ == "__main__": data = u.readfile(u.AOC_2021 + "\\13\\input_a.txt", Integer=False) folds = u.readfile(u.AOC_2021 + "\\13\\input_b.txt", Integer=False) max_x = 0 max_y = 0 coords = [] for d in data: val = d.split(",") coords.append([int(val[0]), int(val[1])]) if int(val[0]) >= max_x: max_x = int(val[0]) + 1 if int(val[1]) >= max_y: max_y = int(val[1]) + 1 print(max_x, max_y) a = np.zeros((max_y, max_x)) for c in coords: print(c)
import os import re import common.util as u #import common.comp as c import logging import time import copy #data = u.readfile(u.AOC_2020 + "\\17\\input.txt") data = u.readfile(u.AOC_2020 + "\\17\\input_ex.txt") class Point: def __init__(self,x,y,z,w): self.x = x self.y = y self.z = z self.w = w def print(self): print("{:02}, {:02}, {:02},{:02}".format(self.x,self.y,self.z,self.w)) class Cube: def __init__(self,x,y,z,w,state): self.p = Point(x,y,z,w) self.x = self.p.x self.y = self.p.y self.z = self.p.z self.w = self.p.w
import os import re import common.util as u #print(os.getcwd()) cmds = u.readfile(u.AOC_2021 + "\\4\\input_test.txt",Integer=False)[0] raw_boards = u.readfile(u.AOC_2021 + "\\4\\input2_test.txt",Integer=False) print(cmds) class Board: W = 5 H = 5 def __init__(self,id,data): self.won = False self.id = id self.data = [] self.called = [] self.hits = [0] * (self.W*self.H) for i in data: for j in i.split(): self.data.append(j) def print(self): print(self.data) def call(self,val): self.called.append(val) if self.won: return False if val in self.data: index = self.data.index(val) self.hits[index] = 1 return True
import os import re import common.util as u #import common.comp as c import logging import time import copy #data = u.readfile(u.AOC_2020 + "\\18\\input.txt") raw = u.readfile(u.AOC_2019 + "\\18_input_ex.txt") class Pos: x = 0 y = 0 DIR_NORTH = 1 DIR_SOUTH = 2 DIR_WEST = 3 DIR_EAST = 4 def __init__(self, x, y): self.x = x self.y = y def north(self): self.y -= 1 def south(self): self.y += 1