Skip to content

Commit

Permalink
Trying out gmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Fazendaaa committed Dec 11, 2024
1 parent 1549f6a commit 44eca91
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/r/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN [ "apk", "add", "--no-cache", \
"font-liberation", \
"g++", \
"gcc", \
"gmp-dev", \
"gfortran", \
"harfbuzz-dev", \
"jpeg-dev", \
Expand Down
10 changes: 7 additions & 3 deletions src/r/R/problem-26.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
# * http://stackoverflow.com/a/8927009/7092954
# * https://zach.se/project-euler-solutions/26/

recurringCycle <- function(number, digits) {

#'
#' @importFrom gmp pow.bigz
#'
recurringCycle <- function(digits) {
index <- 1

while (index < digits) {
if (1 == 10**index %% digits) {
if (1 == pow.bigz(10, index) %% digits) {
return (index)
}

Expand All @@ -49,7 +53,7 @@ problem26 <- function(limit) {
index <- 2

while (index <= limit) {
match <- recurringCycle(1, index)
match <- recurringCycle(index)

if (match > maxMatch) {
maxMatch <- match
Expand Down
11 changes: 11 additions & 0 deletions src/r/renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,17 @@
],
"Hash": "5899f1eaa825580172bb56c08266f37c"
},
"gmp": {
"Package": "gmp",
"Version": "0.7-5",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"methods"
],
"Hash": "47b774de7ee40f6134cfdeab3fc85df9"
},
"goodpractice": {
"Package": "goodpractice",
"Version": "1.0.5",
Expand Down

0 comments on commit 44eca91

Please sign in to comment.