0 Followers
0 Following
3 Posts

a remnant from the old times

This comment demonstrates a misunderstanding of shepherd’ and guix. Using an actual programming language vs some bastardized version of a markup language to describe complex configurations is increasingly popular __because it is better__. guixis inspired bynixand allows you to specify the entire system as code in a reproducible manner - which you don’t want to do in 'human readable’toml+, yaml+`, etc. because it fucking sucks.

Calls for this, calls for that, but the blood money machine keeps on chugging.

python

solution

import aoc def setup(): dm = [int(x) for x in aoc.get_lines(9, stripped=True)[0]] ldm = len(dm) d = [] f = 0 for i in range(0, ldm, 2): lfi = dm[i] d.extend([f] * lfi) f += 1 if i + 1 < ldm: lfr = dm[i + 1] d.extend([-1] * lfr) return d def one(): d = setup() h = 0 t = len(d) - 1 while h < t: if d[h] == -1: while t > h and d[t] == -1: t -= 1 if t > h: d[h], d[t] = d[t], d[h] t -= 1 h += 1 print(sum(i * v for i, v in enumerate(d) if v != -1)) def two(): d = setup() md = max(d) for fid in range(md, -1, -1): fis = [i for i, v in enumerate(d) if v == fid] if not fis: continue s, e = fis[0], fis[-1] + 1 l, f, fi = e - s, 0, None for i in range(s): if d[i] == -1: if f == 0: fi = i f += 1 if f == l: break else: f, fi = 0, None if fi is not None and f == l: d[fi:fi+l] = [fid]*l d[s:e] = [-1]*l print(sum(i * v for i, v in enumerate(d) if v != -1)) one() two() ```

Hey, you. You’re finally awake. You were trying to cross the border, right?

You all are already supervillains, you’re just worried about cannibalism here _alt_man.

python

solution

from math import gcd import aoc def setup(): lines = aoc.get_lines(8, stripped=True) ll = len(lines) ats = [(x, y, f) for y, r in enumerate(lines) for x, f in enumerate(r.strip()) if f != ‘.’] return ll, ats def fa(ats, ll, rh=False): ans = set() fm = {f: [(x, y) for x, y, z in ats if z == f] for f in {z[2] for z in ats}} for f, cd in fm.items(): lans = len(cd) if rh: if lans > 1: ans.update(cd) for i in range(lans): x1, y1 = cd[i] for j in range(i + 1, lans): x2, y2 = cd[j] dx, dy = x2 - x1, y2 - y1 g = gcd(dx, dy) dx, dy = dx // g, dy // g x3, y3 = x1 - dx, y1 - dy if rh: for k in range(-ll, ll): x, y = x1 + k * dx, y1 + k * dy if 0 <= x < ll and 0 <= y < ll: ans.add((x, y)) else: x3, y3 = x1 - dx, y1 - dy x4, y4 = x2 + dx, y2 + dy if 0 <= x3 < ll and 0 <= y3 < ll: ans.add((x3, y3)) if 0 <= x4 < ll and 0 <= y4 < ll: ans.add((x4, y4)) return ans def one(): ll, ats = setup() s = len(fa(ats, ll)) assert s == 269 print(s) def two(): ll, ats = setup() s = len(fa(ats, ll, rh=True)) assert s == 949 print(s) one() two()

Schotts actually provides TLCL for free, and last updated it a month ago:

www.linuxcommand.org/tlcl.php

Linux Command Line Books by William Shotts

Linux Command Line Books by William Shotts

Schotts provides a free ‘internet edition’ .pdf of TLCL, last updated 11/1/2024:

www.linuxcommand.org/tlcl.php

Linux Command Line Books by William Shotts

Linux Command Line Books by William Shotts

It’s not a long lived project, it’s a puzzle, and once solved never needs to run again. My objective here is to get the correct answer, not win a style contest.

python

45s on my machine for first shot, trying to break my will to brute force 😅. I’ll try improving on it in a bit after I smoke another bowl and grab another drink.

solution

from itertools import product import re import aoc def ltr(e): r = int(e[0]) for i in range(1, len(e), 2): o = e[i] n = int(e[i + 1]) if o == ‘+’: r += n elif o == ‘*’: r *= n elif o == ‘||’: r = int(f"{r}{n}“) return r def one(): lines = aoc.get_lines(7) rs = [] for l in lines: d = [int(x) for x in re.findall(r’\d+‘, l)] t = d[0] ns = d[1:] ops = list(product([’+', ‘*’], repeat=len(ns) - 1)) for o in ops: e = str(ns[0]) for i, op in enumerate(o): e += f” {op} {ns[i + 1]}" r = ltr(e.split()) if r == t: rs.append(t) break print(sum(rs)) def two(): lines = aoc.get_lines(7) rs = [] for l in lines: d = [int(x) for x in re.findall(r’\d+‘, l)] t = d[0] ns = d[1:] ops = list(product([’+', ‘*’, ‘||’], repeat=len(ns) - 1)) for o in ops: e = str(ns[0]) for i, op in enumerate(o): e += f" {op} {ns[i + 1]}" r = ltr(e.split()) if r == t: rs.append(t) break print(sum(rs)) one() two()