[2023][ruby][11.1]

main
Alpha Chen 12 months ago
parent 47ca37d8c2
commit 1118280a6e
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -0,0 +1,13 @@
image = ARGF.read
image.gsub!(/^(\.+)$/m, "\\1\n\\1")
image = image.split("\n").map(&:chars).transpose.map(&:join).join("\n")
image.gsub!(/^(\.+)$/m, "\\1\n\\1")
image = image.split("\n").map(&:chars)
galaxies = image.flat_map.with_index {|row, y|
row.filter_map.with_index {|elem, x| elem == ?# ? [y,x] : nil }
}
p galaxies.combination(2).sum {|a, b|
a.zip(b).sum { (_1 - _2).abs }
}
Loading…
Cancel
Save