-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp39.R
More file actions
30 lines (25 loc) · 673 Bytes
/
Copy pathp39.R
File metadata and controls
30 lines (25 loc) · 673 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
#p = 840
#no. of sols = 8
#time = 0.162 seconds
main <- function(){
pmt <- proc.time()
pp <- 1001 #less than p
b <- seq(pp) #c=b
bc <- outer(b,b,"getP")
pbc <- isInt(bc)
pss <- bc[which(pbc==1)]
pss <- pss[pss<pp]
print(table(pss)[table(pss)==max(table(pss))]/2)
#p is top number, number of sols is half bottom number.
proc.time()-pmt
}
#{20,48,52}, {24,45,51}, {30,40,50}
getP <- function(bb,cc){
sqrt(bb^2 + cc^2) + bb + cc
}
getA <- function(bb,cc){
sqrt(bb^2 + cc^2)
}
isInt <- function(x){# returns 0 for non-int and 1 for integers
floor(floor(x)/x)
}