Simulate the factorable probability
Now we will use the is_factorable
function that we wrote in the previous exercise to check factorability of many quadratics.
Specifically, we will check every combination of a
, b
and c
where each value is between 1 and 100, using a nested for
loop.
This exercise is part of the course
Probability Puzzles in R
Exercise instructions
- Write a nested
for
loop, to loop each ofa
,b
, andc
from the values 1 through 100. - For each combination of
a
,b
andc
, check whether the quadratic is factorable.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
counter <- 0
# Nested for loop
for(___){
for(___){
for(___){
# Check whether factorable
if(___){
counter <- counter + 1
}
}
}
}
print(counter / 100^3)