I subsequently realized there is an efficient simple algorithm utilizing properties of the Greatest Common Divisor, as I noted here. Reproduced:
- Write a Greatest Common Divisor function
- Note that the Smallest Common Multiple (SCM) of any two numbers a and b is the value:
a * b / GCD(a,b) .
- Calculate the SCM for the first two numbers of the range; then successively calculate the SCM for that value plus the next value in the range until you hit the end of the range.
I suggest that the challenge be:
- Immediately preceded by a Write a GCD function challenge;
- Be pre-populated with the GCD function just written by the student; and
- Be supplemented with my algorithm note above (or at least the comment
Note that the Smallest Common Multiple (SCM) of any two numbers a and b is the value:
a * b / GCD(a,b)
I believe this would be far more valuable to students than the existing challenge structure.
This is just one person’s opinion, but I don’t think that this challenge is too demanding. One of the objections I have to most online coding education platforms is that they hold your hand to the point that you don’t actually learn much more than syntax. FCC is ramping students up into pretty difficult projects, and as the challenges progress they require not just more logical problem solving but also practical problem solving in the form of research. It is not uncommon for some of the more advanced challenges to take hours or even for students to find that they need to walk away from it and come back again.
Yes, having to work though a math-based challenge when you do not have a lot of experience or confidence in math is frustrating, but it’s a very realistic frustration that is part of this field and something that we need to know how to work though in order to work independently.
This would not be the first time I knew too much math - and initially used the wrong math for a problem.
After first solving this challenge on Friday evening, I was motivated to revisit it by a question on this site by a student who was struggling with time-out crashes in his browser. Since prime factorization is (I believe) far better known than the Euclidean algorithm for calculating GCD, that student may not be the only one to fall into the trap.
FWIW: Once I got past my muttering, the challenge of solving this challenge using prime factorization ended up being quite enjoyable - creating a solution that is almost as efficient as the GCD method.
I think that this challenge is one of the ones that gives that great “I defeated it” satisfaction.