Skip to content

Commit 4f0e90e

Browse files
authored
Merge pull request #32 from bitlux/dev
Add solution for GCAQK4F
2 parents 23b7d18 + d7978c3 commit 4f0e90e

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

gcaqk4f_square_roots/main.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/keep94/sqroot/v3"
7+
)
8+
9+
func main() {
10+
n := sqroot.Sqrt(3)
11+
for _, x := range []int{2, 1, 3, 68, 500187, 325001, 263263} {
12+
fmt.Printf("%d", n.At(x))
13+
}
14+
fmt.Println()
15+
16+
fmt.Println(sqroot.FindFirst(sqroot.Sqrt(12), []int{9, 9, 9, 9, 9, 9, 9, 9, 9}))
17+
18+
const (
19+
length = 200_000
20+
target = 900_000
21+
)
22+
sum := 0
23+
24+
n = sqroot.Sqrt(2)
25+
for index, value := range n.All() {
26+
sum += value
27+
if index >= length {
28+
sum -= n.At(index - length)
29+
}
30+
if sum == target {
31+
fmt.Println(index - length + 1)
32+
break
33+
}
34+
}
35+
}

go.mod

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
module github.com/bitlux/caches
22

33
go 1.23
4+
5+
require github.com/keep94/sqroot/v3 v3.7.2
6+
7+
require github.com/keep94/consume2 v0.7.0 // indirect

go.sum

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/keep94/consume2 v0.7.0 h1:JbS/XxmPbHgEG+1pvGEGc192nCOEx+S/DmJBZz9fkvQ=
4+
github.com/keep94/consume2 v0.7.0/go.mod h1:oI2GS5jRbaWtXBO3wLiqr+dHpNmEyOgAJd4C1Jxp9o0=
5+
github.com/keep94/sqroot/v3 v3.7.2 h1:mSwU0IRjqGtt6uNbatbnffhodz3AIu1Q3L2yx+M64YI=
6+
github.com/keep94/sqroot/v3 v3.7.2/go.mod h1:qRCXiPkBEi3hBGvHAKZjmBlZCZVMn2WRIZeVsYFUo+c=
7+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
10+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
11+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
12+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)