Tom K. answered 10/10/20
Knowledgeable and Friendly Math and Statistics Tutor
Let 1 = kayaking, 2 = sailing , 3 = land-based sports, and 4 = none
The easiest way to do this problem is to write 8 loops 1-4 and count all cases where the adjacent loops don't add up to 3 (the multiplication in the code accomplishes this) and each of 1-3 occurs at least once (the z vector accomplishes this).
I got a total count of 14894
The R code is below. The tempfile written out will allow you to check that the code worked.
count <- 0
tempfile <- c(a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0)
for(a in 1:4){
for(b in 1:4){
for(c in 1:4){
for(d in 1:4){
for(e in 1:4){
for(f in 1:4){
for(g in 1:4){
for(h in 1:4){
#check if no adjacent different water sports
if((a+b-3)*(b+c-3)*(c+d-3)*(d+e-3)*(e+f-3)*(f+g-3)*(g+h-3) != 0){
z <- rep(0,times=3)
y <- c(a,b,c,d,e,f,g,h)
for(loop in 1:8){if(y[loop] != 4){z[y[loop]] <- 1}}
#check that all sports are included at least once
if(z[1]*z[2]*z[3] > 0){
tempfile <- rbind(tempfile,y)
count <- count + 1}}
}}}}}}}}
print(count)
tempfile <- data.frame(tempfile)
tempfile <- tempfile[-1,]
write.csv(tempfile,row.names=FALSE)
Zarif A.
Thank you very much!10/16/20