Big update: Adding all advent of codes to same repo
This commit is contained in:
39
AdventOfCode2015/day1/day1.go
Normal file
39
AdventOfCode2015/day1/day1.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Println("Day 1")
|
||||
start := time.Now()
|
||||
|
||||
dat, err := ioutil.ReadFile("day1.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var floor int64 = 0
|
||||
basement := -1
|
||||
|
||||
for i, value := range dat {
|
||||
|
||||
if basement == -1 && floor == -1 {
|
||||
basement = i
|
||||
}
|
||||
|
||||
if value == 40 {
|
||||
floor++
|
||||
} else if value == 41 {
|
||||
floor--
|
||||
}
|
||||
}
|
||||
|
||||
elapsed := time.Since(start)
|
||||
fmt.Printf("Part 1: %v %v \n", floor, elapsed)
|
||||
fmt.Printf("Part 2: %v %v", basement, elapsed)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user