70 lines
1.0 KiB
Go
70 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
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 total int
|
|
var wentToBasement bool
|
|
var procIdx int
|
|
for _, k := range input {
|
|
for i := range k {
|
|
procIdx++
|
|
if k[i] == '(' {
|
|
total++
|
|
} else if k[i] == ')' {
|
|
total--
|
|
}
|
|
if total < 0 && !wentToBasement {
|
|
wentToBasement = true
|
|
fmt.Printf("Went to basement at direction #%d\n", procIdx)
|
|
}
|
|
}
|
|
}
|
|
fmt.Printf("Santa should go to floor %d\n", total)
|
|
|
|
fmt.Println("\nBen's Solution:")
|
|
bens()
|
|
}
|
|
|
|
func bens() {
|
|
file, err := os.Open("./input")
|
|
floor := 0
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
defer file.Close()
|
|
for {
|
|
data := make([]byte, 1)
|
|
_, err := file.Read(data)
|
|
if err != nil {
|
|
break
|
|
}
|
|
if data[0] == '(' {
|
|
floor = floor + 1
|
|
} else {
|
|
floor = floor - 1
|
|
}
|
|
|
|
}
|
|
fmt.Printf("Floor: %d\n", floor)
|
|
} |