Right: I should have considered all permutations, rather than only those following the natural ordering of the prime factors…

]]>Tkanks, I ‘ve got it now. However I think that there are certain products in your code that are not being checked. For example when x=4 and the factors are 1 2 2 2 3 7, do you check (2*2*3) * (2*7) ?

I have tried the following code:

library(schoolmath)

for (x in 1:23) {

fact = c(1, prime.factor(x * (46 – x)))

print(fact)

ve <- vector()

for (i in 1:(length(fact) – 1)) {

total = fact

first <- combn(total, i, MARGIN=2)

second <- apply(first, 2, function(z) total[is.na(pmatch(total, z))])

if (is.null(dim(second)))

second <- matrix(second, ncol = length(second))

for (j in 1:ncol(first)) {

u = 0

u = u + 1 – is.prim(prod(first[, j]) + prod(second[, j]) – 1)

if (u == 1 & !(prod(first[, j]) %in% ve)) {

cat('x=',x," y=",46-x," first=",prod(first[, j])," second=",prod(second[, j]),"\n")}

ve <- c(ve,prod(first[, j]),prod(second[, j]))

}

}

}

1. Sarah observed x+y. She deduced from s = x+y-1 (= 45) not being a prime that Primrose could not infer (x,y) from x*y=p, since the only case when Primrose can deduce the pair from the product is when the product p is a prime number (or p=1). After solving the puzzle we know Sarah is correct since she observed s=46 and Primrose observed 45 = 5*9 = 15*3 = 45*1.

2. Now, Primrose knows that the decomposition of 45 = x*y is such that x+y-1 is not a prime number. This eliminates (5,9) since 5+9-1=13 is prime. And this eliminates (15,3) since 15+3-1=17 is prime. The only possibility is (45,1), hence Primrose infers that s=46.

3. We know from the puzzle text that s=46, so we have to look at other possible products producing a sum of 46. However those other products p always include (p,1) as a possible decomposition, so there cannot be unicity in the derivation of (x,y). QED