Started working on day 17

This commit is contained in:
2018-12-17 16:53:07 -06:00
parent 08c6209701
commit 3f65da791c
4 changed files with 1989 additions and 1 deletions

View File

@@ -42,8 +42,11 @@ func part1() {
}
}
var ticks int
func part2() {
for len(cartMap) > 1 {
ticks++
sort.Sort(ByPos(carts))
for _, c := range carts {
if *c != 0 {
@@ -54,6 +57,7 @@ func part2() {
for pos := range cartMap {
fmt.Printf("🔵: %0.0f,%0.0f\n", real(pos), imag(pos))
}
fmt.Println("Ticks: ", ticks)
}
type Cart struct {
@@ -69,7 +73,7 @@ func (c *Cart) tick() bool {
delete(cartMap, c.pos)
c.pos += c.dir
if cart, ok := cartMap[c.pos]; ok {
fmt.Printf("❌: %0.0f,%0.0f\n", real(c.pos), imag(c.pos))
fmt.Printf("❌: %0.0f,%0.0f (%d ticks)\n", real(c.pos), imag(c.pos), ticks)
// Remove the cart we crashed into from the map
delete(cartMap, c.pos)
// And clear the cart's pos, we can ignore them now