Skip to content

Commit

Permalink
2015 Day 25 - part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Magiczne committed Nov 12, 2024
1 parent 4873b34 commit eb5dfd6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions 2015/d25/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
To continue, please consult the code grid in the manual. Enter the code at row 2947, column 3029.
57 changes: 57 additions & 0 deletions 2015/d25/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"regexp"

"github.com/Magiczne/AdventOfCode/util"
)

// f(1, 1) = 20151125
// f(1, 2) = f(1, 1) * 252533 % 33554393
// f(2, 1) = f(1, 2) * 252533 % 33554393

// f(1) = 20151125
// f(2) = f(1) * 252533 % 33554393
// f(3) = f(2) * 252533 % 33554393
// f(100) = f(99) * 252533 % 33554393

func getCode(n int) int {
if n == 1 {
return 20151125
}

return getCode(n-1) * 252533 % 33554393
}

// Map column and row to the position in the sequence
func getSequencePosition(column int, row int) int {
return ((row+column-2)*(row+column-1))/2 + column
}

func part1(data []int) int {
row := data[0]
column := data[1]
sequencePosition := getSequencePosition(column, row)

return getCode(sequencePosition)
}

func part2(data []int) int {
return -1
}

func main() {
lineRegexp := regexp.MustCompile(`([0-9]+)[a-z, ]+(\d+)`)
reader := func(name string) []int {
file := util.ReadFile(name)
matches := lineRegexp.FindStringSubmatch(file)

return []int{
util.StringToInt(matches[1]),
util.StringToInt(matches[2]),
}
}

util.TestRuns("25", reader, part1, part2)
util.SolutionRuns("25", reader, part1, part2)
}
1 change: 1 addition & 0 deletions 2015/d25/test-runs/0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
To continue, please consult the code grid in the manual. Enter the code at row 3, column 4.

0 comments on commit eb5dfd6

Please sign in to comment.