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 Day03
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
+ PRIORITIES = [ nil ] + ( 'a' ..'z' ) . to_a + ( 'A' ..'Z' ) . to_a
13
+
14
+ # @example
15
+ # day.part1 #=> 157
16
+ def part1
17
+ @input
18
+ . split ( "\n " )
19
+ . map { |line | line . chars }
20
+ . map { |items | items
21
+ . each_slice ( ( items . length /2.0 ) . floor )
22
+ . to_a
23
+ . reduce ( &:& )
24
+ }
25
+ . flatten
26
+ . map { |common_item | PRIORITIES . index ( common_item ) }
27
+ . reduce ( &:+ )
28
+ end
29
+
30
+ def part2
31
+ end
32
+
33
+ def real_input
34
+ File . read ( '../inputs/day03-input.txt' )
35
+ end
36
+
37
+ EXAMPLE_INPUT = <<~INPUT
38
+ vJrwpWtwJgWrhcsFMMfFFhFp
39
+ jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
40
+ PmmdzqPrVvPwwTWBwg
41
+ wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
42
+ ttgJtRGJQctTZtZT
43
+ CrZsJsPPZsGzwwsLwLmpwMDw
44
+ INPUT
45
+ end
You can’t perform that action at this time.
0 commit comments