File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Day06
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
+ def part1
13
+ start_of_packet_marker ( @input )
14
+ end
15
+
16
+ def part2
17
+ end
18
+
19
+ # @example
20
+ # day.start_of_packet_marker('mjqjpqmgbljsphdztnvjfqwrcgsmlb') => 7
21
+ #
22
+ # @example
23
+ # day.start_of_packet_marker('bvwbjplbgvbhsrlpgdmjqwftvncz') => 5
24
+ #
25
+ # @example
26
+ # day.start_of_packet_marker('nppdvjthqldpwncqszvftbrmjlhg') => 6
27
+ #
28
+ # @example
29
+ # day.start_of_packet_marker('nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg') => 10
30
+ #
31
+ # @example
32
+ # day.start_of_packet_marker('zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw') => 11
33
+ #
34
+ def start_of_packet_marker ( buffer )
35
+ chars = buffer . tr ( "\n " , "" ) . chars
36
+ scan = 3
37
+ found = false
38
+ while !found || scan < chars . length do
39
+ check = chars [ scan -3 ..scan ]
40
+ if check . uniq . length == 4
41
+ found = true
42
+ break
43
+ end
44
+ scan += 1
45
+ end
46
+ return scan + 1
47
+ end
48
+
49
+ def real_input
50
+ File . read ( '../inputs/day06-input.txt' )
51
+ end
52
+
53
+ EXAMPLE_INPUT = <<~INPUT
54
+ mjqjpqmgbljsphdztnvjfqwrcgsmlb
55
+ INPUT
56
+ end
You can’t perform that action at this time.
0 commit comments