diff --git a/progress.png b/progress.png index 905a526..4dcc7f8 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index b0e2791..9ac4b5c 100644 --- a/progress.yaml +++ b/progress.yaml @@ -43,4 +43,4 @@ 22: stars: 1 23: - stars: 1 \ No newline at end of file + stars: 2 \ No newline at end of file diff --git a/src/day23/puzzle2.typ b/src/day23/puzzle2.typ index e69de29..e0c4202 100644 --- a/src/day23/puzzle2.typ +++ b/src/day23/puzzle2.typ @@ -0,0 +1,65 @@ +#import "/src/utils.typ": * + +#let bron-kerbosch(links, R, P, X) = { + if P.len() == 0 and X.len() == 0 { + return if R.len() > 2 { + R.sorted() + } else { + none + } + } + + let longest-len = 0 + let longest = none + let to-visit = P + for v in to-visit { + let neighbors = links.at(v) + let clique = bron-kerbosch( + links, + R + (v,), + P.filter(n => n in neighbors), + X.filter(n => n in neighbors) + ) + if clique != none { + let l = clique.len() + if longest == none or l > longest-len { + longest = clique + longest-len = l + } + } + let _ = P.remove(0) + X.push(v) + } + return longest +} + +#let solve(input) = { + let links = input.split("\n") + + let links-dict = (:) + + let to-test = () + for link in links { + let (a, b) = link.split("-") + if a not in links-dict { + links-dict.insert(a, ()) + } + if b not in links-dict { + links-dict.insert(b, ()) + } + links-dict.at(a).push(b) + links-dict.at(b).push(a) + } + + let clique = bron-kerbosch(links-dict, (), links-dict.keys(), ()) + + return clique.join(",") +} + +#show-puzzle( + 23, 2, + solve, + example: "co,de,ka,ta", + only-example: true +) +#show-result("ab,al,cq,cr,da,db,dr,fw,ly,mn,od,py,uh") \ No newline at end of file diff --git a/src/main.pdf b/src/main.pdf index 67cb60b..fc1d30a 100644 Binary files a/src/main.pdf and b/src/main.pdf differ