-
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
951f419
commit 060fbbc
Showing
12 changed files
with
281 additions
and
4 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
....#..... | ||
.........# | ||
.......... | ||
..#....... | ||
.......#.. | ||
.......... | ||
.#..^..... | ||
........#. | ||
#......... | ||
......#... |
Large diffs are not rendered by default.
Oops, something went wrong.
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,20 @@ | ||
package day6 | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
"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: | ||
log.Fatalf("unknown part: %s", part) | ||
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,109 @@ | ||
package day6 | ||
|
||
import ( | ||
"os" | ||
|
||
"strings" | ||
|
||
"github.com/timredband/advent-of-code/pkg/utils" | ||
) | ||
|
||
type Position struct { | ||
i int | ||
j int | ||
direction string | ||
} | ||
|
||
func Part1(file *os.File) int { | ||
inputs := utils.ReadFile(file) | ||
|
||
board := make([][]string, len(inputs)) | ||
|
||
position := Position{direction: "north"} | ||
maxPosition := len(inputs) - 1 | ||
|
||
for i, v := range inputs { | ||
line := strings.Split(v, "") | ||
board[i] = line | ||
|
||
for j, c := range line { | ||
if c == "^" { | ||
position.i = i | ||
position.j = j | ||
} | ||
} | ||
} | ||
|
||
for position.i > 0 && position.j < len(inputs) { | ||
board[position.i][position.j] = "X" | ||
|
||
if position.direction == "north" { | ||
if position.i-1 < 0 { | ||
break | ||
} | ||
|
||
if board[position.i-1][position.j] == "#" { | ||
position.direction = "east" | ||
} else { | ||
position.i -= 1 | ||
} | ||
|
||
continue | ||
} | ||
|
||
if position.direction == "south" { | ||
if position.i+1 > maxPosition { | ||
break | ||
} | ||
|
||
if board[position.i+1][position.j] == "#" { | ||
position.direction = "west" | ||
} else { | ||
position.i += 1 | ||
} | ||
|
||
continue | ||
} | ||
|
||
if position.direction == "east" { | ||
if position.j+1 > maxPosition { | ||
break | ||
} | ||
|
||
if board[position.i][position.j+1] == "#" { | ||
position.direction = "south" | ||
} else { | ||
position.j += 1 | ||
} | ||
|
||
continue | ||
|
||
} | ||
|
||
if position.direction == "west" { | ||
if position.j-1 < 0 { | ||
break | ||
} | ||
|
||
if board[position.i][position.j-1] == "#" { | ||
position.direction = "north" | ||
} else { | ||
position.j -= 1 | ||
} | ||
|
||
continue | ||
} | ||
} | ||
|
||
result := 0 | ||
|
||
for _, row := range board { | ||
for _, v := range row { | ||
if v == "X" { | ||
result += 1 | ||
} | ||
} | ||
} | ||
|
||
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,7 @@ | ||
package day6 | ||
|
||
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
# advent-of-code | ||
asadasd# advent-of-code | ||
|