Skip to content

Commit 9647e16

Browse files
author
Robb Kidd
committed
day 12, part 2 ... kinda
example input passes, but hnnnnnn it's slow: Day12#part2#test_0001_ = 1.65 s = . Does not fly for real input.
1 parent c582fe7 commit 9647e16

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

2023/ruby/day12.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ def part1
1616
.reduce(&:+)
1717
end
1818

19-
# example
20-
# #day.part2 #=> 'how are you'
19+
# @example
20+
# day.part2 #=> 525152
2121
def part2
22+
@hot_springs ||= HotSprings.new(input)
23+
24+
@hot_springs
25+
.unfold
26+
.map { |even_more_springs, even_more_damaged_counts|
27+
@hot_springs.scan(even_more_springs, even_more_damaged_counts)
28+
}
29+
.reduce(&:+)
2230
end
2331

2432
EXAMPLE_INPUT = <<~INPUT
@@ -48,6 +56,20 @@ def initialize(input="")
4856
}
4957
end
5058

59+
# @example super simple
60+
# new(".# 1").unfold #=> [ [".#?.#?.#?.#?.#", [1,1,1,1,1]] ]
61+
# @example 1st row
62+
# new("???.### 1,1,3").unfold #=> [ ["???.###????.###????.###????.###????.###", [1,1,3,1,1,3,1,1,3,1,1,3,1,1,3]] ]
63+
def unfold
64+
rows
65+
.map { |springs, damaged_counts|
66+
[
67+
([springs] * 5).join("?"),
68+
damaged_counts * 5,
69+
]
70+
}
71+
end
72+
5173
WORKING = "."
5274
DAMAGED = "#"
5375
UNKNOWN = "?"

0 commit comments

Comments
 (0)