and day 25!

This commit is contained in:
David 2020-12-26 15:41:44 -05:00
parent 16784775c9
commit f1d6903fba

54
25/main.go Normal file
View File

@ -0,0 +1,54 @@
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)
}