@ -136,3 +136,16 @@ func NumberSpiral(row, col int) int64 {
return result
}
// I could not have solved it wothout the help of
// https://japlslounge.com/posts/cses/two_knights/1.htm
func TwoKnights(n int) []int {
result := []int{}
for i := 1; i <= n; i++ {
positions := i*i*(i*i-1)/2 - (i-2)*(i-1)*4
result = append(result, positions)
@ -56,3 +56,7 @@ func TestNumberSpiral(t *testing.T) {
assert.Equal(t, int64(871712102163621276), NumberSpiral(586095107, 933655238))
assert.Equal(t, int64(999999997000000003), NumberSpiral(999_999_999, 999_999_999))
func TestTwoKnights(t *testing.T) {
assert.Equal(t, []int{0, 6, 28, 96, 252, 550, 1056, 1848}, TwoKnights(8))