[2024][ruby][19.2]

main
Alpha Chen 3 days ago
parent 6f46272340
commit ce1cc4b097
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -2,8 +2,18 @@ available, desired = DATA.read.split("\n\n")
available = available.split(", ")
desired = desired.lines(chomp: true)
available = Regexp.new("^(#{available.join(?|)})+$")
pp desired.select { _1 =~ available }.size
available_r = Regexp.new("^(#{available.join(?|)})+$")
pp desired.select { _1 =~ available_r }.size
ways = Hash.new {|h,k|
h[k] = available
.select { k.start_with?(_1) }
.map { k.sub(_1, "") }
.sum { h[_1] }
}
ways[""] = 1
pp desired.sum { ways[_1] }
__END__
r, wr, b, g, bwu, rb, gb, br

Loading…
Cancel
Save