Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Day 23

2024/day23.livemd

Day 23

Mix.install([:kino_aoc, {:libgraph, github: "bitwalker/libgraph"}, :combination])

Section

{:ok, puzzle_input} =
  KinoAOC.download_puzzle("2024", "23", System.fetch_env!("LB_ADVENT_OF_CODE_SESSION"))
{:ok,
 "on-za\nbp-hs\nvc-bg\ntm-us\nzf-ox\nib-lc\nuo-zs\nov-qj\nll-eb\niy-tq\nbg-by\nun-ix\ngi-do\nrv-ou\nyp-qu\nqb-um\nqs-dn\nru-ro\net-fw\nyx-jt\nns-iz\nod-rc\nny-ap\nvb-fd\nwf-wr\nyh-qy\nfa-ct\nqo-fv\nig-jv\nqi-ff\nnj-ii\nsa-gg\ncp-un\nez-kh\nvs-du\ngp-qs\npt-qj\nyp-my\njf-sz\nyo-gm\nfn-xw\niu-xr\nse-ox\nmw-ie\nfw-br\nxy-iu\nqw-wi\nxc-dq\nvb-cq\ntw-zj\nka-aq\ngo-ds\nvi-cn\npz-kz\npy-nd\npt-ws\nog-lw\nlb-hj\nef-ac\ncv-qa\nsq-jv\nfw-xk\nlu-fc\nbj-bp\nzh-fi\ntg-nm\nsp-at\nke-dh\nut-ly\ngr-vr\nko-qg\nxg-df\nrc-up\nbd-it\ngz-en\nqj-ev\nwf-dx\nxn-hi\npq-th\nkr-gw\ngu-sm\ncv-xr\nzq-fp\nep-kq\nfv-dx\nlc-rw\ney-ef\nek-rw\ntw-eg\nfc-zw\nxm-ho\ngj-oy\nhy-og\nec-tw\npy-hw\nqr-jh\nvh-ea\nvz-ja\nov-ev\nyh-vh\nyk-fc\nfm-yi\nyf-kx\ner-bi\nbi-qq\ngc-fk\nie-gf\njk-fn\nxl-il\nbs-dl\nsh-op\npy-vx\ncn-jl\ntl-ee\nxw-wn\nzv-br\nkr-yn\ndj-wd\nwj-bz\nhf-bg\nzh-ql\nbs-ls\ntq-jk\nmz-dz\nav-jr\ngj-dr\npo-iy\nof-aq\nun-fw\nnv-bx\njz-n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\nke-fa\nmx-jn\ndq-ew\nax-ow\nhv-dx\nyh-sx\ngx-ry\njz-jv\nsb-wj\ndo-ok\ngj-qn\nbr-ri\nlu-zw\nsb-ge\nkg-ao\nuu-fp\nus-xh\ndd-jb\nxp-wi\ncf-cj\nhm-zj\nle-sa\nwf-ty\nqx-xq\noi-rr\nbl-og\nmq-hj\ndw-xi\naw-ap\nsk-cs\nwu-yq\ngm-zq\nna-ry\nwp-pj\nne-gy\ndt-yn\nau-bm\nrk-ur\nnm-oi\naf-zm\ncd-ss\ndj-ez\ncf-oy\nce-md\nth-kz\nnt-cd\nrm-iz\njz-fs\nni-qo\njx-do\nzy-xe\nls-uq\nsy-jt\nwa-xh\nlf-lv\nys-jt\nij-wg\njw-mw\nbk-ef\nyx-ek\nvr-cm\njv-sk\ndw-ej\nmo-pq\nov-pl\nfz-ge\nmt-ep\ncq-hz\nza-zc\nlj-uy\nrv-ae\nse-ln\nkw-ze\nwo-ln\nvo-zw\nwd-fd\nxo-pl\nmx-gc\nln-lr\nsy-rw\ngy-fs\nzy-ea\nkc-er\nfl-l" <> ...}
connections =
  puzzle_input
  |> String.split("\n", trim: true)
  |> Enum.map(fn <> ->
    {a, b}
  end)
[
  {"on", "za"},
  {"bp", "hs"},
  {"vc", "bg"},
  {"tm", "us"},
  {"zf", "ox"},
  {"ib", "lc"},
  {"uo", "zs"},
  {"ov", "qj"},
  {"ll", "eb"},
  {"iy", "tq"},
  {"bg", "by"},
  {"un", "ix"},
  {"gi", "do"},
  {"rv", "ou"},
  {"yp", "qu"},
  {"qb", "um"},
  {"qs", "dn"},
  {"ru", "ro"},
  {"et", "fw"},
  {"yx", "jt"},
  {"ns", "iz"},
  {"od", "rc"},
  {"ny", "ap"},
  {"vb", "fd"},
  {"wf", "wr"},
  {"yh", "qy"},
  {"fa", "ct"},
  {"qo", "fv"},
  {"ig", "jv"},
  {"qi", "ff"},
  {"nj", "ii"},
  {"sa", "gg"},
  {"cp", "un"},
  {"ez", "kh"},
  {"vs", "du"},
  {"gp", "qs"},
  {"pt", "qj"},
  {"yp", "my"},
  {"jf", "sz"},
  {"yo", "gm"},
  {"fn", "xw"},
  {"iu", "xr"},
  {"se", "ox"},
  {"mw", "ie"},
  {"fw", "br"},
  {"xy", "iu"},
  {"qw", "wi"},
  {"xc", "dq"},
  {"vb", ...},
  {...},
  ...
]
party =
  Graph.new(type: :undirected)
  |> Graph.add_edges(connections)
#Graph
cliques = Graph.cliques(party)
[
  ["yf", "dk", "dy", "hm", "vx", "zj", "ec", "eg", "ko", "kx", "tw", "ux"],
  ["yf", "dk", "hm", "vx", "zj", "ec", "eg", "qg", "ko", "kx", "tw", "ux"],
  ["yf", "ob"],
  ["xa", "wl", "lx", "lq", "jy", "in", "hy", "lw", "qd", "fu", "ub", "og"],
  ["xa", "wl", "lx", "jy", "bl", "in", "hy", "lw", "qd", "fu", "ub", "og"],
  ["xa", "wi"],
  ["bd", "cb", "it", "ut", "fq", "hs", "ur", "ly", "tx", "yg", "ui", "gl"],
  ["bd", "cb", "it", "ut", "fq", "ur", "ly", "tx", "yg", "ui", "gl", "rk"],
  ["bd", "bu"],
  ["nm", "qb", "gv", "nf", "oi", "tg", "uj", "yd", "rr", "tr", "vv", "mg"],
  ["nm", "qb", "gv", "nf", "oi", "tg", "uj", "yd", "rr", "tr", "vv", "zp"],
  ["nm", "ge"],
  ["dk", "jn"],
  ["cn", "lh", "di", "xm", "cm", "oe", "vi", "ho", "fg", "mt", "io", "dv"],
  ["cn", "zt"],
  ["cn", "jl"],
  ["qp", "xd"],
  ["qp", "zq", "qk", "uu", "cy", "fp", "ay", "yo", "gm", "vj", "ps", "fr"],
  ["qp", "zq", "qk", "uu", "cy", "ay", "yo", "gm", "vj", "jl", "ps", "fr"],
  ["xq", "qx", "rg", "wc", "um", "rv", "ae", "kw", "lj", "ze", "wq", "ou"],
  ["xq", "kg"],
  ["xq", "qo"],
  ["ti", "et", "bu", "xk", "ix", "fw", "un", "ri", "cp", "br", "gr", "ch"],
  ["ti", "et", "bu", "xk", "fw", "un", "ri", "cp", "br", "gr", "ch", "yw"],
  ["ti", "ab"],
  ["nh", "hv", "id", "ap", "fv", "ny", "pb", "ni", "aw", "nx", "vk", "qo"],
  ["nh", "pj"],
  ["nh", "lk"],
  ["ys", "ib", "dg", "vr", "yx", "jt", "ek", "lt", "sy", "vm", "lc", "rw"],
  ["ys", "ib", "dg", "yx", "jt", "pg", "ek", "lt", "sy", "vm", "lc", "rw"],
  ["ys", "tl"],
  ["cb", "ha"],
  ["ue", "dd", "kd", "zm", "kt", "il", "af", "xx", "vl", "xl", "jd", "rx"],
  ["ue", "dd", "kd", "kt", "il", "af", "xx", "vl", "xl", "jd", "rx", "pz"],
  ["ue", "bh"],
  ["jg", "cx", "fo", "ro", "ru", "oo", "dh", "as", "zx", "ke", "om", "gu"],
  ["jg", "cx", "fo", "ro", "ru", "dh", "as", "sm", "zx", "ke", "om", "gu"],
  ["jg", "cy"],
  ["bz", "fz", "qi", "tn", "xg", "dc", "ge", "sb", "df", "hu", "vd", ...],
  ["bz", "ae"],
  ["bz", "gm"],
  ["im", "dz", "ab", "sz", "ej", "mz", "pv", "rj", ...],
  ["im", "dz", "sz", "ej", "mz", "pv", "rj", ...],
  ["im", "ps"],
  ["sw", "gc", "si", "aj", "is", ...],
  ["sw", "gc", "si", "aj", ...],
  ["sw", "fn"],
  ["cg", "zt", ...],
  ["cg", ...],
  [...],
  ...
]

Part 1

cliques
|> Stream.flat_map(fn clique ->
  if length(clique) >= 3 do
    Combination.combine(clique, 3)
  else
    []
  end
end)
|> Stream.filter(fn clique -> Enum.any?(clique, &amp;String.starts_with?(&amp;1, "t")) end)
|> MapSet.new()
|> MapSet.size()
1248

Part 2

cliques
|> Enum.max_by(&amp;length/1)
|> Enum.sort()
|> Enum.join(",")
"aa,cf,cj,cv,dr,gj,iu,jh,oy,qr,xr,xy,zb"