Discussion 2-7

Today we started by coding most of HW4. To save time I skipped some parts that I bet you can do pretty easily. The code we wrote is hw4.cpp.

After that, we tried solving this problem from the online contest website projecteuler. This was good practice with setting up tricky nested loops. The code we produced is here.

Extra challenges

We can think of the loop problem as finding the first positive integer divisible by 1 through M, where M = 20 for the problem on the website. Here are some challenges to potentially extend the ideas we were using. For the harder challenges, the comments in the bottom of the code from class can get you on the right track. Definitely email if you want to discuss any of these - or just to check your answers!

  1. Make sure you understand the code for that loop problem! If you kinda get it but aren't quite sure, it can help to code+debug it yourself without referring to my code. Of course, for testing/debugging you should use small cases like M = 1,2,3, or 10 instead of going for the full M=20 right away.
  2. Solve the case M = 25. Just a slight change from the problem we solved in class, but it's enough to necessitate some code optimization...
  3. Solve the case M = 50. This one is not happening unless you figure out the math trick. Also you'll probably need WolframAlpha's help with the final multiplication step.
  4. Solve the case M = 1000. This probably needs significant extra effort to deal with the huge numbers...