You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
14 lines
391 B
14 lines
391 B
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 }
|
|
}
|