-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp41.R
More file actions
39 lines (34 loc) · 816 Bytes
/
Copy pathp41.R
File metadata and controls
39 lines (34 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# [1] 7652413
# user system elapsed
# 0.334 0.000 0.333
# Nine numbers cannot be done (1+2+3+4+5+6+7+8+9=45 => always dividable by 3)
# Eight numbers cannot be done (1+2+3+4+5+6+7+8=36 => always dividable by 3)
main <- function(){
pmt <- proc.time()
library(numbers)
upper <- 7654321 #987654321 #largest 9 digit pandigital
repeat{
upper <- previousPrime(upper)
if(isPan(upper)){
print(upper)
break
}
}
print(proc.time()-pmt)
}
isPan <- function(z){
y <- sepDig(z)
ll <- seq(length(y))
bool <- 0
for(i in ll){
if(i %in% y){
bool <- bool + 1
}
}
if(bool==length(y)){
return(TRUE)
}else{FALSE}
}
sepDig <- function(x){
as.numeric(strsplit(as.character(x),"")[[1]])
}