Compare commits
2 Commits
6a82336c99
...
db685a1290
| Author | SHA1 | Date | |
|---|---|---|---|
| db685a1290 | |||
| 27a56dc7cd |
@@ -35,15 +35,14 @@ func parseInstructions(data []string) []instruction {
|
||||
return instructions
|
||||
}
|
||||
|
||||
func PartOne(data []string) int {
|
||||
instructions := parseInstructions(data)
|
||||
func execute(instructions []instruction) (accumulator int, terminatedNormally bool) {
|
||||
visited := make(map[int]bool)
|
||||
accumulator := 0
|
||||
accumulator = 0
|
||||
pc := 0
|
||||
|
||||
for pc < len(instructions) {
|
||||
if visited[pc] {
|
||||
return accumulator
|
||||
return accumulator, false
|
||||
}
|
||||
visited[pc] = true
|
||||
|
||||
@@ -59,6 +58,12 @@ func PartOne(data []string) int {
|
||||
}
|
||||
}
|
||||
|
||||
return accumulator, true
|
||||
}
|
||||
|
||||
func PartOne(data []string) int {
|
||||
instructions := parseInstructions(data)
|
||||
accumulator, _ := execute(instructions)
|
||||
return accumulator
|
||||
}
|
||||
|
||||
|
||||
@@ -21,3 +21,11 @@ func TestPartOne(t *testing.T) {
|
||||
t.Errorf("PartOne() = %d, want %d", got, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPartTwo(t *testing.T) {
|
||||
expected := 8
|
||||
got := PartTwo(testInput)
|
||||
if got != expected {
|
||||
t.Errorf("PartOne() = %d, want %d", got, expected)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user