package main import ( "bufio" "fmt" "os" "strconv" "time" ) func main() { start := time.Now() partOne() duration := time.Since(start) fmt.Printf("p1: %s, p2: n/a\n", duration) } func partOne() { f, _ := os.Open("input") reader := bufio.NewReader(f) scanner := bufio.NewScanner(reader) scanner.Scan() doorPubKey, _ := strconv.Atoi(scanner.Text()) scanner.Scan() cardPubKey, _ := strconv.Atoi(scanner.Text()) subjectNumber := 7 value := 1 magicPrime := 20201227 loopCount := 1 doorLoopCount := 0 cardLoopCount := 0 for { value = (value * subjectNumber) % magicPrime if value == doorPubKey { doorLoopCount = loopCount } if value == cardPubKey { cardLoopCount = loopCount } loopCount = loopCount + 1 if doorLoopCount != 0 && cardLoopCount != 0 { break } } value = 1 subjectNumber = cardPubKey for i := 0; i < doorLoopCount; i = i + 1 { value = (value * subjectNumber) % magicPrime } fmt.Println(value) }