Discussion 2/2

Today we went over the midterm in class, and also worked on the following problem:

Problem 1

Find the smallest positive number that is divisible by all numbers between 1 and 20.

This problem was taken from Project Euler. This site has a ton of good problems in the math/programming area. They start out pretty straightforward, but become difficult FAST.

We solved this problem in 3 steps, shown here in 3 different files

    // Take just one number, try to divide it by everything between 1 and 20.

    // Apply the code from divide1.cpp in a loop to test each number one at a time.

    // Make a few small changes that dramatically speed up the runtime.

Most of the content of today's lecture was the whole process of building our solution step by step. I don't really know how to display this online, so if you missed the lecture then that kind of stinks :(

Problem 2 (if we have extra time)

Write a program that inputs a number of seconds from the user, and outputs the same amount of time written in units of hours, minutes, and seconds.

For example, if the user inputs 3663 then your program should output 1 hour, 1 minute, and 3 seconds. If the user inputs 139 then your program should output 0 hours, 2 minutes, and 19 seconds.

Side note: Your computer actually does this. There's something called "Coordinated Universal Time". It measures time by counting the number of seconds passed since Thursday, Jan 1, 1970. This is often the way your computer keeps track of time. So all the time values in your computer are stored purely in units of seconds. To make it readable to us, it takes the value in seconds and converts it to a standard date. That's pretty much what I'm asking you to do, except they also keep track of days, months, and years.