[2023][ruby][12.1]

main
Alpha Chen 12 months ago
parent eeb3633702
commit 2928c03ce0
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -0,0 +1,14 @@
p ARGF.readlines(chomp: true).map {|row|
springs, groups = row.split(" ")
[springs, groups.scan(/\d+/).map(&:to_i)]
}.map {|springs, groups|
unknowns = springs.count(??)
(0...2**unknowns).map {|arrangement|
arrangement = arrangement.to_s(2).rjust(unknowns, ?0).chars.map { _1 == ?0 ? ?. : ?# }
candidate = springs.gsub(??) { arrangement.shift }
candidate.chars
.slice_when { _1 != _2 }
.reject { _1[0] == ?. }
.map(&:size) == groups
}.count(&:itself)
}.sum
Loading…
Cancel
Save