parent
eeb3633702
commit
2928c03ce0
@ -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…
Reference in new issue