Combine AoC Repos
This commit is contained in:
70
2015/day06/main.go
Normal file
70
2015/day06/main.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var input []string
|
||||
var readInp string
|
||||
for {
|
||||
_, err := fmt.Scan(&readInp)
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
log.Fatal(err)
|
||||
}
|
||||
break
|
||||
}
|
||||
input = append(input, readInp)
|
||||
}
|
||||
|
||||
var lights [][]int
|
||||
for i := 0; i < 1000; i++ {
|
||||
lights = append(lights, make([]int, 1000))
|
||||
}
|
||||
for i := range input {
|
||||
if input[i] == "on" || input[i] == "off" || input[i] == "toggle" {
|
||||
stX, stY := parseLocations(input[i+1])
|
||||
endX, endY := parseLocations(input[i+3])
|
||||
for ix := stX; ix <= endX; ix++ {
|
||||
for iy := stY; iy <= endY; iy++ {
|
||||
if input[i] == "on" {
|
||||
lights[ix][iy]++
|
||||
} else if input[i] == "off" {
|
||||
if lights[ix][iy] > 0 {
|
||||
lights[ix][iy]--
|
||||
}
|
||||
} else if input[i] == "toggle" {
|
||||
lights[ix][iy] += 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var brightness int
|
||||
for i := 0; i < 1000; i++ {
|
||||
for j := 0; j < 1000; j++ {
|
||||
brightness += lights[i][j]
|
||||
}
|
||||
}
|
||||
fmt.Printf("Brightness: %d\n", brightness)
|
||||
}
|
||||
|
||||
func parseLocations(s string) (int, int) {
|
||||
dirSplit := strings.Split(s, ",")
|
||||
return assertAtoi(dirSplit[0]), assertAtoi(dirSplit[1])
|
||||
}
|
||||
|
||||
func assertAtoi(s string) int {
|
||||
ret, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
fmt.Println("Error in Atoi: " + s)
|
||||
os.Exit(1)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
Reference in New Issue
Block a user