From 9aec8d35b05ffc8200bcde88293eaf40153b8764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sun, 22 Dec 2019 20:50:57 +0100 Subject: [PATCH] Finish 2/1 --- 2/main.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/2/main.go b/2/main.go index 4a70552..ff80356 100644 --- a/2/main.go +++ b/2/main.go @@ -1,11 +1,10 @@ package main import ( - "bufio" "fmt" - "os" - - "git.xenrox.net/xenrox/aoc2019/tools" + "io/ioutil" + "strconv" + "strings" ) func calcOpcode(lines []int) int { @@ -29,19 +28,27 @@ func calcOpcode(lines []int) int { return 0 } -func main() { +func parseInput(file string) []int { var lines []int - file, err := os.Open("input.txt") + dat, err := ioutil.ReadFile(file) if err != nil { fmt.Println("Error") } - defer file.Close() - scanner := bufio.NewScanner(file) - lines, err := tools.ScanFileInt("input.txt") - if err != nil { - fmt.Println("Error") + split := strings.Split(strings.TrimSpace(string(dat)), ",") + for _, val := range split { + i, err := strconv.Atoi(val) + if err != nil { + fmt.Println("Error") + } + lines = append(lines, i) } + return lines +} + +func main() { + lines := parseInput("input.txt") lines[1] = 12 lines[2] = 2 + fmt.Println(lines) fmt.Println(calcOpcode(lines)) } -- 2.44.0