sos <- sumofsquares(100, 6) # 23 solutions
head(sos)
table(rowSums(!is.na(sos)))
# one solution with one or two x_i
# five solutions with four x_i
# six solutions with five x_i
# ten solutions with six x_i
rowSums(sos^2, na.rm=TRUE) # all 100
sos <- sumofsquares(100, 6, zerosum=TRUE)
head(sos)
rowSums(sos^2, na.rm=TRUE) # all 100
rowSums(sos, na.rm=TRUE) # all 0
Run the code above in your browser using DataLab