
Title:
Algorithm Pseudocode  Intro to Computer Science

Description:

Let's try to write down an algorithm that systematizes how we solve it. And

we're going to write this as pseudocode. That means we're not worrying about the

details of how to write exactly correct Python. We're trying to get the idea

down and see if it makes sense. So let's think about how we solve the problem as

a human again. Here's how we start it. We looked at our start date, which was

January 24. And we counted the number of days remaining in January. We do that

by just counting up. If we started earlier we might not want to have counted

every day. So we can subtract the total number of days in January from the day

we started. So that will be our starting point. And we're going to keep the

results in a variable called days and we'll start by initializing days into the

number of days in the card line minus the day that we're starting on. So, for

the example, that was 31, for the number of days in January, minus 24, which, I

believe is 7. And once we've done that, well, we finished month1, so we should

increase the value of month1 by 1. So now we were at February and now we started

going through the months, until we got to the month we are on. So we went

through each month until we got up to the month we were looking for, which was

June. So that's sort of like a while loop. We're doing something over and over

again until we get to the stopping condition. So we can write that as

pseudocode. We're going to keep going while the current month is less than the

target month. We're going to add the number of days in the current month. And

we're going to increase the current month by 1. Now, we're not quite done we

still need to account for the day in the month that we arrived at. And there we

just add that day so if it was day one of June then we would add one. If we

didn't actually get in to June. Now, we're going to add 29 since the 29th was

our target day. We haven't yet accounted for years, for this example it was

okay. But, for other cases, we're going to need to account for years, so let's

think about how to do that. We can do it similarly to how we accounted for

month. Well, we're not up to the same year. We're going to add the number of

days in that year.