1
0
Fork 0

Day twenty-three

This commit is contained in:
Andrew Tomaka 2024-12-23 12:07:26 -05:00
parent 2167efbb3a
commit 94e04cc796
Signed by: atomaka
GPG key ID: 61209BF70A5B18BE
2 changed files with 3458 additions and 0 deletions

3380
23/input Normal file

File diff suppressed because it is too large Load diff

78
23/main.rb Executable file
View file

@ -0,0 +1,78 @@
#!/usr/bin/env ruby
input = (ARGV.first.nil? ? DATA : ARGF)
.readlines(chomp: true)
.map { _1.split("-") }
connections = Hash.new { _1[_2] = Set.new }
input.each do |connection|
a, b = connection.sort
connections[a] << b
connections[b] << a
end
parties = Set.new
connections.dup.each do |(node, neighbors)|
neighbors.each do |neighbor|
connections[neighbor].each do |neighbors_neighbor|
if neighbors.include?(neighbors_neighbor)
parties << [node, neighbor, neighbors_neighbor].sort
end
end
end
end
p parties.select { |party| party.any? { _1.match?(/^t/) } }.size
largest = []
connections.keys.each do |node|
(connections[node].size + 1).downto(1) do |size|
(connections[node] + [node]).to_a.combination(size) do |group|
if group.all? { |a| group.all? { |b| a == b || connections[a].include?(b) } }
if largest.size < group.size
largest = group
break
end
end
end
break if largest.size == size
end
end
p largest.sort.join(",")
__END__
kh-tc
qp-kh
de-cg
ka-co
yn-aq
qp-ub
cg-tb
vc-aq
tb-ka
wh-tc
yn-cg
kh-ub
ta-co
de-co
tc-td
tb-wq
wh-td
ta-ka
td-qp
aq-cg
wq-ub
ub-vc
de-ta
wq-aq
wq-vc
wh-yn
ka-de
kh-ta
co-tc
wh-qp
tb-vc
td-yn