-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26.r
More file actions
21 lines (18 loc) · 646 Bytes
/
Copy path26.r
File metadata and controls
21 lines (18 loc) · 646 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
recur.length <- function (n) {
x = 1 # Starting with the numerator 1
remainders = c(x)
repeat {
x = (x*10) %% n # Find the remainder
if (x == 0) { return (0) } # Fraction terminates, so cycle length is 0.
if ((x %in% remainders)) {break} # Repeating remainder is found. Break from loop.
remainders <- c(remainders, x)
#print(remainders) # Else add remainder to list.
}
return (length(remainders) - which(remainders == x) + 1) # Exclude non-repeating part of the decimal
}
k = c()
for (d in 1:999) {
k = c(k,recur.length(d))
}
max(k)
which(k %in% max(k))