There is a school with 1,000 students and 1,000 lockers. On the first day of term the headteacher asks the first student to go a
long and open every single locker, he asks the second to go to every second locker and close it, the third to go to every third locker and close it if it is open or open it if it is closed, the fourth to go to the fourth locker and so on. The process is completed with the thousandth student. How many lockers are open at the end?
CONST Faux = 0 CONST Vrai = NOT (Faux) CONST nb = 1000 DIM SHARED locker(nb) AS INTEGER DIM i AS INTEGER, j AS INTEGER, answer AS INTEGER '1 first student FOR i = 1 TO nb: locker(i) = Vrai: NEXT i: ' CALL See '2 2nd student FOR i = 2 TO nb STEP 2: locker(i) = Faux: NEXT i: 'CALL See FOR j = 3 TO nb FOR i = j TO nb STEP j locker(i) = NOT (locker(i)) NEXT i 'CALL See NEXT j answer = 0 FOR i = 1 TO nb IF locker(i) THEN answer = answer + 1 NEXT i PRINT "answer="; answer END
SUB See
SHARED locker() AS INTEGER DIM i AS INTEGER locker(0) = 0 FOR i = 1 TO nb PRINT locker(i); IF locker(i) THEN locker(0) = locker(0) + 1 NEXT i PRINT locker(0)
The way to correctly solve this problem is by ignoring the 300,000 dollar home part, and simply add the mortgage and the tax which comes out to 7432.26