[2023][ruby][13.1]

main
Alpha Chen 11 months ago
parent 31afd41329
commit 21e4174051
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -0,0 +1,14 @@
patterns = ARGF.read.split("\n\n")
.map { _1.split("\n").map(&:chars) }
def find_fold(pattern)
(0.5...pattern.length-0.5).step(1).find {|fold|
a = pattern[0..fold.floor]
b = pattern[fold.ceil..]
a.reverse.zip(b).reject { _1.any?(&:nil?) }.all? { _1 == _2 }
}&.ceil
end
verts = patterns.map { find_fold(_1.transpose) }.compact
hors = patterns.map { find_fold(_1) }.compact
p verts.sum + hors.sum { _1 * 100 }
Loading…
Cancel
Save