Solved #28
This commit is contained in:
parent
53a5b94525
commit
1bda83d514
57
pe28/pe28.go
Normal file
57
pe28/pe28.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package pe28
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Matrix struct {
|
||||
arr []int
|
||||
width int
|
||||
}
|
||||
|
||||
func (m Matrix) GetIndex(row, col int) int {
|
||||
return m.arr[m.width*row+col]
|
||||
}
|
||||
|
||||
func (m *Matrix) SetIndex(row, col, val int) {
|
||||
m.arr[m.width*row+col] = val
|
||||
}
|
||||
|
||||
func (m Matrix) String() {
|
||||
for row := 0; row < m.width; row++ {
|
||||
fmt.Println(m.arr[row*m.width : row*m.width+m.width])
|
||||
}
|
||||
}
|
||||
|
||||
func Solve(_ []string) {
|
||||
/*
|
||||
//width := 1001
|
||||
width := 10
|
||||
num_numbers := width * width
|
||||
mat := Matrix{
|
||||
arr: make([]int, num_numbers),
|
||||
width: width,
|
||||
}
|
||||
i := num_numbers
|
||||
cur_width
|
||||
for i > 0; {
|
||||
for y := width - 1; y >= 0; y-- {
|
||||
mat.SetIndex(x, y, i)
|
||||
i--
|
||||
}
|
||||
}
|
||||
//fmt.Println(mat)
|
||||
mat.String()
|
||||
*/
|
||||
max_width := 1001
|
||||
sum := 1
|
||||
for width := 1; width < max_width; width += 2 {
|
||||
width_squared := width * width
|
||||
|
||||
sum += width_squared + width + 1 +
|
||||
width_squared + 2*(width+1) +
|
||||
width_squared + 3*(width+1) +
|
||||
width_squared + 4*(width+1)
|
||||
}
|
||||
fmt.Println("Sum of diagonals =", sum)
|
||||
}
|
|
@ -6,11 +6,13 @@ import (
|
|||
|
||||
"shillerben.com/gitlab/shillerben/projecteuler-go/pe26"
|
||||
"shillerben.com/gitlab/shillerben/projecteuler-go/pe27"
|
||||
"shillerben.com/gitlab/shillerben/projecteuler-go/pe28"
|
||||
)
|
||||
|
||||
var solve_funcs = map[string]func([]string){
|
||||
"26": pe26.Solve,
|
||||
"27": pe27.Solve,
|
||||
"28": pe28.Solve,
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user