Skip to content

Commit

Permalink
add day 5 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrikss committed Dec 5, 2022
1 parent fc64e26 commit 6edc75c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions day5.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,24 @@ func main() {
moves, _ := strconv.Atoi(instructions[1])
from, _ := strconv.Atoi(instructions[3])
to, _ := strconv.Atoi(instructions[5])
for i := 0; i < moves; i++ {
pop := len(crates[from]) - 1
crates[to] = append(crates[to], crates[from][pop])
crates[from] = crates[from][:pop]
if false { // part 1
for i := 0; i < moves; i++ {
pop := len(crates[from]) - 1
crates[to] = append(crates[to], crates[from][pop])
crates[from] = crates[from][:pop]
}
} else { // part 2
pop := len(crates[from])
crates[to] = append(crates[to], crates[from][pop-moves:pop]...)
crates[from] = crates[from][:pop-moves]
}
}

part1 := ""
result := ""
for i := 1; i < len(crates); i++ {
pop := len(crates[i]) - 1
part1 += crates[i][pop]
result += crates[i][pop]
}

fmt.Println("part 1: ", part1)
fmt.Println("part 2: ", 0)
fmt.Println("solution: ", result)
}

0 comments on commit 6edc75c

Please sign in to comment.