My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update utils and starter with `HASH()` function

+8 -1
+1 -1
2023/starter.py
··· 7 7 from utils import parse_line, parse_nums, mul, all_unique, factors, memoize, primes, resolve_mapping 8 8 from utils import chunks, parts, gcd, lcm, print_grid, min_max_xy 9 9 from utils import new_table, transposed, rotated, firsts, lasts 10 - from utils import md5, sha256, VOWELS, CONSONANTS 10 + from utils import md5, sha256, VOWELS, CONSONANTS, HASH 11 11 from utils import Point, DIRS, DIRS_4, DIRS_8, N, NE, E, SE, S, SW, W, NW 12 12 # Itertools Functions: 13 13 # product('ABCD', repeat=2) AA AB AC AD BA BB BC BD CA CB CC CD DA DB DC DD
+7
2023/utils.py
··· 381 381 s.update(msg) 382 382 return s.hexdigest() 383 383 384 + def HASH(code): 385 + val = 0 386 + for c in code: 387 + val += ord(c) 388 + val *= 17 389 + val %= 256 390 + return val 384 391 385 392 def knot_hash(msg): 386 393 lengths = [ord(x) for x in msg] + [17, 31, 73, 47, 23]