-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxnAnalysis.R
47 lines (38 loc) · 960 Bytes
/
xnAnalysis.R
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
39
40
41
42
43
44
45
46
47
###
### xnAnalysis.R
### Calculates the Smaug sequence using C++ output
###
output <- read.csv(".../output.txt") # change your directory responsibly
N = 10000 # match N with the passed parameter from pp.cpp
primeOutput = unique(output$Prime1)
###
### Obtain List of Primes Under N
###
prime_numbers <- function(n) {
if (n >= 2) {
x = seq(2, n)
prime_nums = c()
for (i in seq(2, n)) {
if (any(x == i)) {
prime_nums = c(prime_nums, i)
x = c(x[(x %% i) != 0], i)
}
}
return(prime_nums)
}
else
{
stop("Input number should be at least 2.")
}
}
primes = prime_numbers(N)
###
### Outputs the Primes that Require an Additional Base to Obtain a Prime Mirror to Form a Palindrome
###
current = 0
for(i in primes){
if(output$Base[which(output$Prime1==i)][1] > current){
current = output$Base[which(output$Prime1==i)][1]
cat(i, " ")
}
}