Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
digidis committed Dec 12, 2018
1 parent a1f3d84 commit 6d9136d
Show file tree
Hide file tree
Showing 23 changed files with 5,057 additions and 0 deletions.
1 change: 1 addition & 0 deletions digidis-go/README.md
@@ -0,0 +1 @@
# adventofcode
40 changes: 40 additions & 0 deletions digidis-go/day1/day1.go
@@ -0,0 +1,40 @@
package main

import (
"fmt"
"io/ioutil"
"strconv"
"strings"
)

func main() {
var (
v, step int
counts = make(map[int]bool)
)
data, _ := ioutil.ReadFile("input.txt")
rows := strings.Split(string(data), "\n")
for {
for _, r := range rows {
if r[0] == '+' {
v += atoi(r[1:])
} else {
v -= atoi(r[1:])
}
if counts[v] {
fmt.Println(v)
return
}
counts[v] = true
}
if step == 0 {
fmt.Println(v)
}
step++
}
}

func atoi(s string) int {
i, _ := strconv.Atoi(s)
return i
}

0 comments on commit 6d9136d

Please sign in to comment.