File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Day04
2
+ def self . go
3
+ day = new
4
+ puts "Part 1: #{ day . part1 } "
5
+ puts "Part 2: #{ day . part2 } "
6
+ end
7
+
8
+ def initialize ( input = nil )
9
+ @input = input || real_input
10
+ end
11
+
12
+ # @example
13
+ # day.part1 => 2
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
+ }
23
+ . map { |assign_a , assign_b |
24
+ assign_a . cover? ( assign_b ) || assign_b . cover? ( assign_a )
25
+ }
26
+ . select { |fully_contains | fully_contains == true }
27
+ . count
28
+ end
29
+
30
+ def part2
31
+ end
32
+
33
+ def real_input
34
+ File . read ( '../inputs/day04-input.txt' )
35
+ end
36
+
37
+ EXAMPLE_INPUT = <<~INPUT
38
+ 2-4,6-8
39
+ 2-3,4-5
40
+ 5-7,7-9
41
+ 2-8,3-7
42
+ 6-6,4-6
43
+ 2-6,4-8
44
+ INPUT
45
+ end
You can’t perform that action at this time.
0 commit comments