I am trying to solve a quiz using R, but my code does not work properly. I tried debugging, but it seems that the ifelse statement fails to work at certain numbers that seem
You have a binary problem. There is no reason to use ifelse. Work with logical values:
ifelse
bulbs <- rep(FALSE, 100) for (i in 1:100) bulbs[!((1:100) %% i)] <- !bulbs[!((1:100) %% i)] which(bulbs) #[1] 1 4 9 16 25 36 49 64 81 100