Skip to content

Commit

Permalink
Day 5 done
Browse files Browse the repository at this point in the history
  • Loading branch information
bogosj committed Jan 13, 2020
1 parent 97866d9 commit c9e3985
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions 2017/day5/main.go
Expand Up @@ -13,11 +13,16 @@ type instructions struct {
pc int
}

func (i *instructions) run() (ret int) {
func (i *instructions) run(strange bool) (ret int) {
for i.pc >= 0 && i.pc < len(i.i) {
o := i.pc
i.pc += i.i[i.pc]
i.i[o]++
offset := i.i[i.pc]
i.pc += offset
if strange && offset >= 3 {
i.i[o]--
} else {
i.i[o]++
}
ret++
}
return
Expand All @@ -33,10 +38,12 @@ func input() *instructions {

func part1() {
i := input()
fmt.Printf("It takes %d steps to exit the program\n", i.run())
fmt.Printf("It takes %d steps to exit the program\n", i.run(false))
}

func part2() {
i := input()
fmt.Printf("It takes %d steps to exit the program with strange\n", i.run(true))
}

func main() {
Expand Down

0 comments on commit c9e3985

Please sign in to comment.