DEV Community

Cover image for DAY 1 - Advent of Code 2020 w/ GoLang
Edvin
Edvin

Posted on • Edited on

DAY 1 - Advent of Code 2020 w/ GoLang

DAY 1:
O(n^3) 😅

package days

import (
    "fmt"

    inputs "../inputs"
)

// One : advent of code, day one part1 and 2
func One() {
    inputSlice := inputs.Day1

    for i := 0; i < len(inputSlice); i++ {
        for j := i + 1; j < len(inputSlice); j++ {
            for y := j + 1; y < len(inputSlice); y++ {
                if (inputSlice[i] + inputSlice[j] + inputSlice[y]) == 2020 {
                    fmt.Println(inputSlice[i] * inputSlice[j] * inputSlice[y])
                }
            }
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

Link to Github source file

Top comments (0)