Archive for bug
weird bug
Posted in Kids, pictures with tags beetle, bug, garden, ladybug, Nezera viridula, raspberries on August 2, 2015 by xi'anLe Monde puzzle [#6]
Posted in R, Statistics with tags bug, Le Monde, mathematical puzzle, prime numbers, schoolmath on February 18, 2011 by xi'anA simple challenge in Le Monde this week: find the group of four primes such that any sum of three terms in the group is prime and the overall sum is minimised. Here is a quick exploration by simulation, using the schoolmath package (with its imperfections):
[sourcecode language=”r” gutter=”false”]
A=primes(start=1,end=53)[-1]
lengthA=length(A)
res=4*53
for (t in 1:10^4){
B=sample(A,4,prob=1/(1:lengthA))
sto=is.prim(sum(B[-1]))
for (j in 2:4)
sto=sto*is.prim(sum(B[-j]))
if ((sto)&(sum(B)<res)){
res=sum(B)
sol=B}
}
}
[/sourcecode]
providing the solution 5 7 17 19.
A subsidiary question in the same puzzle is whether or not it is possible to find a group of five primes such that any sum of three terms is still prime. Running the above program with the proper substitutions of 4 by 5 does not produce any solution, even when increasing the upper boundary in A. So it is most likely that the answer is no.
bug in schoolmath
Posted in R with tags bug, prime factor decomposition, prime numbers, R, schoolmath on June 14, 2010 by xi'anNeil Gunther has pointed out on his blog that the prime number decomposition R package schoolmath contains mistakes in the function primes, listing 1 as a prime number but also including decomposable numbers like 133 in its list of prime numbers:
> primes(100,140)
[1] 101 107 111 113 123 129 131 137
> primes(50,140)
[1] 51 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 133
[20] 137 139
> is.prim(primes(133)
[1] FALSE
> is.prim(primes(200,300))
[1] FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE
[13] TRUE TRUE TRUE TRUE TRUE TRUE
> sum(1-is.prim(primes(1,1000)))
[1] 10
> data(primlist)
> sum(1-is.prim(primlist[1:25000]))
[1] 3309
This is rather annoying and I hope it gets quickly fixed!

