advent2022

Advent of Code 2022 Solutions
git clone git://bsandro.tech/advent2022
Log | Files | Refs | README | LICENSE

commit 0bc797eb7312ca31ff7bf6aaf0d1d8aba55b22ab
parent ce366fbb05172bded7895abc32ab8e31a1dbb268
Author: bsandro <email@bsandro.tech>
Date:   Thu,  1 Dec 2022 06:20:25 +0000

Day 01 go fmt

Diffstat:
Mday01/main.go | 18+++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/day01/main.go b/day01/main.go @@ -1,16 +1,16 @@ package main import ( - "os" + "bufio" "fmt" "log" - "bufio" - "strconv" + "os" "sort" + "strconv" ) func main() { - if (len(os.Args) > 1) { + if len(os.Args) > 1 { day0102(os.Args[1]) } } @@ -18,7 +18,9 @@ func main() { func day0102(input_file string) { fmt.Printf("day 01 input filename: %s\n", input_file) input, err := os.Open(input_file) - if err != nil { log.Fatal(err) } + if err != nil { + log.Fatal(err) + } defer input.Close() scanner := bufio.NewScanner(input) var loads []int @@ -26,7 +28,9 @@ func day0102(input_file string) { for scanner.Scan() { if len(scanner.Text()) > 0 { load, err := strconv.Atoi(scanner.Text()) - if err != nil { log.Fatal(err) } + if err != nil { + log.Fatal(err) + } cur_load += load } else { loads = append(loads, cur_load) @@ -40,7 +44,7 @@ func day0102(input_file string) { cnt := len(loads) fmt.Printf("Max load: %d\n", loads[cnt-1]) if cnt > 3 { - sum3 := loads[cnt-1]+loads[cnt-2]+loads[cnt-3] + sum3 := loads[cnt-1] + loads[cnt-2] + loads[cnt-3] fmt.Printf("Top 3 loads sum: %d\n", sum3) } }