File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -12,14 +12,7 @@ def initialize(input=nil)
12
12
# @example
13
13
# day.part1 => 2
14
14
def part1
15
- @input
16
- . split ( "\n " )
17
- . map { |line | line . split ( "," ) }
18
- . map { |pair |
19
- pair
20
- . map { |elf | elf . split ( "-" ) . map ( &:to_i ) }
21
- . map { |start , stop | Range . new ( start , stop ) }
22
- }
15
+ input_as_ranges
23
16
. map { |assign_a , assign_b |
24
17
assign_a . cover? ( assign_b ) || assign_b . cover? ( assign_a )
25
18
}
@@ -30,6 +23,17 @@ def part1
30
23
def part2
31
24
end
32
25
26
+ def input_as_ranges
27
+ @as_ranges ||= @input
28
+ . split ( "\n " )
29
+ . map { |line | line . split ( "," ) }
30
+ . map { |pair |
31
+ pair
32
+ . map { |elf | elf . split ( "-" ) . map ( &:to_i ) }
33
+ . map { |start , stop | Range . new ( start , stop ) }
34
+ }
35
+ end
36
+
33
37
def real_input
34
38
File . read ( '../inputs/day04-input.txt' )
35
39
end
You can’t perform that action at this time.
0 commit comments