File tree Expand file tree Collapse file tree 1 file changed +10
-25
lines changed
Expand file tree Collapse file tree 1 file changed +10
-25
lines changed Original file line number Diff line number Diff line change @@ -16,45 +16,30 @@ func day7(file string) (part1, part2 int) {
1616 defer f .Close ()
1717 scanner := bufio .NewScanner (f )
1818
19- scanner .Scan ()
20- t := scanner .Bytes ()
21- beams := map [int ]int {}
22- for x , c := range t {
23- if c == 'S' {
24- beams [x ] = 1
25- }
26- }
27-
28- part2 = 1
19+ var beams []int
2920 for scanner .Scan () {
3021 t := scanner .Bytes ()
31- rest := 0
3222 for x , c := range t {
23+ if c == 'S' {
24+ beams = make ([]int , len (t ))
25+ beams [x ] = 1
26+ break
27+ }
3328 if c == '^' && beams [x ] > 0 {
34- split := 0
3529 if x > 0 {
3630 beams [x - 1 ] += beams [x ]
37- split += beams [x ]
3831 }
3932 if x < len (t ) {
4033 beams [x + 1 ] += beams [x ]
41- split += beams [x ]
4234 }
43- delete (beams , x )
44- rest ++
35+ beams [x ] = 0
4536 part1 ++
4637 }
4738 }
48- if rest == 0 {
49- sum := 0
50- for _ , i := range beams {
51- sum += i
52- }
53- // fmt.Println(beams, len(beams), sum)
54- part2 = sum
55- }
5639 }
57-
40+ for _ , i := range beams {
41+ part2 += i
42+ }
5843 return
5944}
6045
You can’t perform that action at this time.
0 commit comments