Skip to content

Commit

Permalink
Update print flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenLightning committed Dec 29, 2019
1 parent 95ebfd5 commit dd24f0d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 14 deletions.
4 changes: 2 additions & 2 deletions day08/main.go
Expand Up @@ -62,9 +62,9 @@ func main() {
for x := 0; x < width; x++ {
switch image[y*width+x] {
case 0:
fmt.Print(" ")
fmt.Print(".")
case 1:
fmt.Print("")
fmt.Print("#")
default:
fmt.Print("?")
}
Expand Down
28 changes: 27 additions & 1 deletion day10/main.go
Expand Up @@ -2,14 +2,19 @@ package main

import (
"bufio"
"flag"
"fmt"
"math"
"os"
"sort"
"strconv"
)

var printFlag = flag.Bool("print", false, "print map as the 200th asteroid is destroyed")

func main() {
flag.Parse()

lines := readLines("input.txt")

asteroids := make(map[Vector2]bool)
Expand Down Expand Up @@ -58,11 +63,32 @@ func main() {
}
}

target := vaporizationOrder[199]

{
fmt.Println("--- Part Two ---")
target := vaporizationOrder[199]
fmt.Println(target.x*100 + target.y)
}

if *printFlag {
for _, asteroid := range vaporizationOrder[200:] {
asteroids[asteroid] = true
}
for y, line := range lines {
for x := range line {
if x == bestLocation.x && y == bestLocation.y {
fmt.Print("X")
} else if x == target.x && y == target.y {
fmt.Print("O")
} else if asteroids[Vector2{x, y}] {
fmt.Print("#")
} else {
fmt.Print(".")
}
}
fmt.Println()
}
}
}

func findVisibleAsteroids(location Vector2, asteroids map[Vector2]bool) []Vector2 {
Expand Down
4 changes: 2 additions & 2 deletions day11/main.go
Expand Up @@ -34,9 +34,9 @@ func main() {
for y := min.y; y <= max.y; y++ {
for x := min.x; x <= max.x; x++ {
if grid[Vector2{x, y}] == 1 {
fmt.Print("")
fmt.Print("#")
} else {
fmt.Print(" ")
fmt.Print(".")
}
}
fmt.Println()
Expand Down
4 changes: 2 additions & 2 deletions day15/main.go
Expand Up @@ -159,9 +159,9 @@ func main() {
} else if !ok {
fmt.Print("?")
} else if value == Path {
fmt.Print(" ")
fmt.Print(".")
} else {
fmt.Print("")
fmt.Print("#")
}
}
fmt.Println()
Expand Down
50 changes: 43 additions & 7 deletions day24/main.go
Expand Up @@ -2,11 +2,18 @@ package main

import (
"bufio"
"flag"
"fmt"
"os"
)

type Layer [5][5]bool

var printFlag = flag.Bool("print", false, "print final state for part two")

func main() {
flag.Parse()

lines := readLines("input.txt")

{
Expand Down Expand Up @@ -60,8 +67,6 @@ func main() {
{
fmt.Println("--- Part Two ---")

type Layer [5][5]bool

var layer Layer
for y, line := range lines {
for x, char := range line {
Expand Down Expand Up @@ -160,17 +165,48 @@ func main() {

bugs := 0
for _, layer := range state {
for y := 0; y < 5; y++ {
for x := 0; x < 5; x++ {
if layer[y][x] {
bugs++
bugs += count(layer)
}

fmt.Println(bugs)

if *printFlag {
for count(state[min]) == 0 && min < max {
min++
}
for count(state[max]) == 0 && min < max {
max--
}
for index := min; index <= max; index++ {
layer := state[index]

fmt.Printf("Depth %d:\n", index)
for y := 0; y < 5; y++ {
for x := 0; x < 5; x++ {
if y == 2 && x == 2 {
fmt.Print("?")
} else if layer[y][x] {
fmt.Print("#")
} else {
fmt.Print(".")
}
}
fmt.Println()
}
}
}
}
}

fmt.Println(bugs)
func count(layer Layer) (bugs int) {
for y := 0; y < 5; y++ {
for x := 0; x < 5; x++ {
if layer[y][x] {
bugs++
}
}
}
return
}

func readLines(filename string) []string {
Expand Down

0 comments on commit dd24f0d

Please sign in to comment.