Created
December 3, 2018 09:59
-
-
Save wgfm/128c22abd26015199ec299629ba76552 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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