-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2010419
commit 21d8fd4
Showing
7 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.......... | ||
.......... | ||
.......... | ||
.......... | ||
.......... | ||
.......... | ||
.......... | ||
.......... | ||
........a. | ||
........a. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
............ | ||
........0... | ||
.....0...... | ||
.......0.... | ||
....0....... | ||
......A..... | ||
............ | ||
............ | ||
........A... | ||
.........A.. | ||
............ | ||
............ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
..................................w............... | ||
.................................................. | ||
.....................................C............ | ||
......................................3........... | ||
.............b.......u.........w...........3...... | ||
...........................u...................... | ||
...8........K...........u.......y.........I....... | ||
..................................P5........B..... | ||
...U................2.P...............B...C....... | ||
............i......x.P........w......s.C......IB5. | ||
..............t....................y....x......... | ||
.......8............K....1.......w............u... | ||
.................i.............r.........s........ | ||
..2.............t..T.K.......r......8..........I.. | ||
8..............t..T.....r...................5..... | ||
...2........................1....M.t...N....x..... | ||
...V....U.......................N.S..........I.... | ||
.........W...i............O....v............S..... | ||
................L...1...s.fT.....x............3... | ||
....6.......C...N.........Tf.3.................... | ||
...6.......F..........V..........k...N......H..... | ||
...................U..f........0......H.y......... | ||
.......................O...P......0............... | ||
.......L..U....m.......R............s............. | ||
6...i.................O....0.2.........H.....B.... | ||
........................R......H.........S........ | ||
......F.....c..........m..............d........... | ||
................F.L.....m..................7...... | ||
.............J.........................S.......... | ||
.b....j.k..............V0......................... | ||
.................L.....K.......................... | ||
.......F.......J..............r.....M............. | ||
......................m1....a.R...7............... | ||
.......4......Y..6.D.............................. | ||
k............9.......D................M........... | ||
.....Xb.................V...h..................... | ||
A.........9.Xl..........D......R.................. | ||
4.............c..d........D.............7......... | ||
.A.4.............c.............M.7.v.............. | ||
..........n.9........................h............ | ||
...j....bd.........f.....p..W..................... | ||
.............k.........p.......................... | ||
.......W4.......p......X.....5..J.....v........... | ||
........W.d..c......A........n..v.....o........... | ||
..........l.....n..........o......Y...h........... | ||
.....A............................................ | ||
..j..........n.................................... | ||
a9.lX..................Y...........o.............. | ||
.......a.................Y..........o............. | ||
...a....l.......................p................. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package day8 | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func Execute(part string, file *os.File) (int, error) { | ||
switch part { | ||
case "1": | ||
return Part1(file), nil | ||
case "2": | ||
return Part2(file), nil | ||
default: | ||
return 0, errors.New(fmt.Sprintf("unknown part: %s", part)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package day8 | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/timredband/advent-of-code/pkg/utils" | ||
) | ||
|
||
type Coordinate struct { | ||
x int | ||
y int | ||
} | ||
|
||
func Part1(file *os.File) int { | ||
inputs := utils.ReadFile(file) | ||
board := make([][]string, len(inputs)) | ||
|
||
for i, v := range inputs { | ||
line := strings.Split(v, "") | ||
board[i] = line | ||
} | ||
|
||
coordinatesByAntenna := make(map[string][]Coordinate) | ||
|
||
for x, row := range board { | ||
for y, val := range row { | ||
if val == "." { | ||
continue | ||
} | ||
|
||
if _, ok := coordinatesByAntenna[val]; !ok { | ||
coordinatesByAntenna[val] = make([]Coordinate, 0) | ||
} | ||
|
||
coordinatesByAntenna[val] = append(coordinatesByAntenna[val], Coordinate{x, y}) | ||
} | ||
|
||
} | ||
|
||
antinodeCoordinates := make(map[Coordinate]struct{}) | ||
|
||
for _, coordinates := range coordinatesByAntenna { | ||
i, j := 0, 1 | ||
|
||
for i < len(coordinates) { | ||
for j < len(coordinates) { | ||
xDiff := coordinates[i].x - coordinates[j].x | ||
yDiff := coordinates[i].y - coordinates[j].y | ||
|
||
firstAntiNode := Coordinate{x: coordinates[i].x + xDiff, y: coordinates[i].y + yDiff} | ||
secondAntiNode := Coordinate{x: coordinates[j].x - xDiff, y: coordinates[j].y - yDiff} | ||
|
||
if firstAntiNode.x >= 0 && firstAntiNode.x < len(board) && firstAntiNode.y >= 0 && firstAntiNode.y < len(board) { | ||
antinodeCoordinates[firstAntiNode] = struct{}{} | ||
} | ||
|
||
if secondAntiNode.x >= 0 && secondAntiNode.x < len(board) && secondAntiNode.y >= 0 && secondAntiNode.y < len(board) { | ||
antinodeCoordinates[secondAntiNode] = struct{}{} | ||
} | ||
|
||
j += 1 | ||
} | ||
|
||
coordinates = coordinates[1:] | ||
|
||
i, j = 0, 1 | ||
} | ||
} | ||
|
||
result := len(antinodeCoordinates) | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package day8 | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
func Part2(file *os.File) int { | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters