advent2022/useful.py

39 lines
986 B
Python
Raw Permalink Normal View History

2022-12-05 21:46:11 +02:00
#!/usr/bin/env python3
from functools import reduce
2022-12-11 13:35:09 +02:00
from itertools import permutations, product, combinations, pairwise, groupby, takewhile
2022-12-11 11:39:54 +02:00
from more_itertools import batched, sliding_window
2022-12-05 21:46:11 +02:00
from collections import defaultdict, deque
import re, sys
import math
import numpy as np
import cv2 as cv
from icecream import ic
def commaline(line):
return [int(n) for n in line.strip().split(',')]
def headerfooter(f):
return f.read().split('\n\n', maxsplit=1)
def pgphs(text):
return text.split('\n\n')
def hfl(f): # header footer lines
return [p.strip().split('\n') for p in headerfooter(f)]
2022-12-11 11:39:54 +02:00
def numbers(l): # usually what we want really
return [int(x) for x in re.findall(r'[-0-9]+', l)]
2022-12-05 21:46:11 +02:00
def lines(f):
return [l.strip() for l in f.readlines()]
def dprint(*args):
sep = False
for arg in args:
if sep:
print('--------')
sep = True
for a, b in arg.items():
print('%10s: %s' % (a, ','.join(b)))
print()