-
Notifications
You must be signed in to change notification settings - Fork 1
/
25.go
59 lines (52 loc) · 922 Bytes
/
25.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"bufio"
"fmt"
"log"
"os"
"regexp"
"strconv"
)
func main() {
file, err := os.Open("input/25.txt")
if err != nil {
log.Fatal(err)
}
var text string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
text = scanner.Text()
}
re := regexp.MustCompile("Enter the code at row ([0-9]+), column ([0-9]+).")
res := re.FindStringSubmatch(text)
if res == nil {
log.Fatal("Regex failed on input", text)
}
row, err := strconv.Atoi(res[1])
if err != nil {
log.Fatal(err)
}
column, err := strconv.Atoi(res[2])
if err != nil {
log.Fatal(err)
}
entry := 0
// find row
for i := 1; i < row; i++ {
entry += i
}
// find column
for i := 1; i < column; i++ {
entry += row + i
}
i := 0
code := 20151125
for {
if i == entry {
fmt.Println(code)
break
}
code = (code * 252533) % 33554393
i++
}
}