You saw this code in the session:
# one input, and several output in simple data structure:
factors=function(number){
# empty vector that will collect output
vectorOfAnswers=c()
# for every value in the sequence...
for (i in 1:number){
#if the remainder of 'number'/'i' equals zero...
if ((number %% i) == 0){
# ...add 'i' to the vector of factors!
vectorOfAnswers=c(vectorOfAnswers,i)
}
}
return (vectorOfAnswers) # returning the vector
}
This function accepted an integer number and returned its factors. Please answer these questions:
For any number N, how many times does the for section is executed to compute the factos of N?
Make a change in the code to reduce the times the for section is executed.
Open the file demo_hdi, it is a csv file in the folder you downloaded. Then,
You should get something like this:
You should get something like this:
You should get something like this:
Keep collecting data (and start if you haven’t).
Be ready to start your experiment soon.