whether student N starts at locker 0 or locker N shouldn't matter - you should end up with 31 either way.
Well, it doesn't matter if you aren't couting locker 0 (in the original problem, there is no locker 0). It does matter if you do count locker 0 since every student toggles locker 0. The point of the solution to the problem is that only those lockers with a square number will be open at the end because an odd number of students have toggled them (since they have an odd number of unique factors). Since 0 has neither an odd nor an even number of factors (it has an infinite number of factors), the final state of locker 0 diverges, unlike the other lockers. If you count locker 0, your answer will actually depend on whether the last student was odd or even. If even (and between floor(sqrt(1000)) and ceiling(sqrt(1000)) you will get 31, but if odd, you will get 32).
I took a glance at your code, and it looks like you're only iterating through 999 students. You do the first two as separate cases, then loop through from 3 to 999. That's 2 + 997 = 999 students. Make that outer loop in Students 3-1000 (i <= NUMBER_OF_STUDENTS) and that should fix it.
true, but if index 0 is locker 0, then there are only really 999 lockers, and you only need 999 students since student 1000 will not change any lockers.
If index 0 is locker 1, then there are actually 2 bugs: the number of students, but also the fact that every student is toggling locker 1 when only one student (student 1) should be.
____________________________
Progress Quest Progress