Skip to content

Instantly share code, notes, and snippets.

@wgfm
Created Dec 3, 2018
Embed
What would you like to do?
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