Skip to content

Instantly share code, notes, and snippets.

@wgfm
Created December 3, 2018 09:59
Show Gist options
  • Save wgfm/128c22abd26015199ec299629ba76552 to your computer and use it in GitHub Desktop.
Save wgfm/128c22abd26015199ec299629ba76552 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)
func main() {
freqs := make(map[int]bool)
total := 0
numbers := data()
Outer:
for {
for _, number := range numbers {
total += number
if freqs[total] {
break Outer
}
freqs[total] = true
}
}
fmt.Println(total)
}
func data() []int {
var buff []int
file, err := os.Open("./one_input")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
number, _ := strconv.Atoi(scanner.Text())
buff = append(buff, number)
}
return buff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment