Math quiz

jazzc

Elite Member
Joined
Jan 27, 2009
Messages
2,964
Reaction score
14,717
Following macdonjo3 's post, here 's a few I remember

A)
Difficulty: Easy.

How much is:
999*998*997*996*...*-996*-997*-998*-999

No calculators :)

B)

Difficulty: Hard. I 've let the number of lockers low so you can bruteforce the result in case the result inspires you to find the analytical solution ;)

There are 20 closed numbered lockers and 20 numbered people (1,2,3...). The person with number 1 goes and opens all 20 lockers. After he finishes, the person with number 2 goes through lockers 2,4,6,8,10,12,14,16,18,20 and closes them. After he finishes, the person with number 3 goes through lockers 3,6,9,12,15,18 and if one is open, he closes it, if it is closed he opens it. Similarly for person number 4 etc.

How many lockers will still be open after the 20th person has finished?

Wanted: The result and a formula for 1 billion lockers and people :)

Please only PM me your answers so that people have the chance to think about it instead of just reading the answers.


Winners so far (sorted alphabetically)

healzer
ionica21
JFoulds
Junkfood00
qrazy
phracktl
SmartMan
tacopalypse
45415

Congratulations to all!
 
Last edited:
A) 0


for question 2... the series you mentioned 3,6,9,12,16,20 is right or a typo??
 
a) 0

It took me about 2 mins of thinking to "get it". :)
 
JFoulds & qrazy are the winners so far! Congratulations guys!

Keep the responses coming! :)
 
hehe. Here's a C program you can use, it's not so efficient but it does the job.

However it crashes at large values because of the 16bit integer I think.

:p

Code:
#include <stdio.h>

#define nrOfLockers 20

int main()
{
    int lockers[nrOfLockers];

    for(int i=0; i<nrOfLockers; i++) {
        lockers[i] = 1;
    }

    for(int i=1; i<nrOfLockers; i=i+2) {
        lockers[i] = 0;
    }

    for(int i=2; i<nrOfLockers; i++) {
        int b = i+1;
        while(b <= nrOfLockers) {
            if(lockers[b-1] == 0) {
                lockers[b-1] = 1;
            }
            else {
                lockers[b-1] = 0;
            }
            b = b+i+1;
        }
    }

    for(int i=0; i<nrOfLockers; i++) {
        if(lockers[i]==1) {
            printf("%d ", i+1);
        }
    }
    return 0;

}
 
hehe. Here's a C program you can use, it's not so efficient but it does the job.

Thanks for the program, it may be useful to people.

Looking forward to your mathematical explanation :)
 
Thanks for the program, it may be useful to people.

Looking forward to your mathematical explanation :)

I really have no explanation for this. I think it's more of a systematic thing than an algebraic expression or whatever. You can do this by hand, it's easy.
 
Nice one. If you had thought of the problem mathematically(with numbers), you could've avoided the extra 'for' loops in the code.....


hehe. Here's a C program you can use, it's not so efficient but it does the job.

However it crashes at large values because of the 16bit integer I think.

:p

Code:
#include <stdio.h>

#define nrOfLockers 20

int main()
{
    int lockers[nrOfLockers];

    for(int i=0; i<nrOfLockers; i++) {
        lockers[i] = 1;
    }

    for(int i=1; i<nrOfLockers; i=i+2) {
        lockers[i] = 0;
    }

    for(int i=2; i<nrOfLockers; i++) {
        int b = i+1;
        while(b <= nrOfLockers) {
            if(lockers[b-1] == 0) {
                lockers[b-1] = 1;
            }
            else {
                lockers[b-1] = 0;
            }
            b = b+i+1;
        }
    }

    for(int i=0; i<nrOfLockers; i++) {
        if(lockers[i]==1) {
            printf("%d ", i+1);
        }
    }
    return 0;

}
 
I really have no explanation for this. I think it's more of a systematic thing than an algebraic expression or whatever. You can do this by hand, it's easy.

Yes, it 's not an algebraic expression, it 's just a small reasoning. The beauty is not to do it by hand though because it 's trivial (you can't bruteforce a billion lockers though) and no one really cares about the actual number anyway. The beauty is to get the solution by means of thinking about it. Which is the reason for having math quizzes in the first place - brain gym :)
 
@SmartMan: PM me the explanation :)
 
I've got 0 for a and 4 for b.

The code I used for b is as follows:
Code:
Sub Main()
        Dim LockerNumber As Integer = 20
        Dim Lockers As New List(Of Boolean)
        For x = 1 To LockerNumber
            Lockers.Add(False)
        Next
        'lockers created
        For x = 1 To LockerNumber
            Dim amount As Integer = LockerNumber / x
            Dim number As Integer
            For y = 1 To amount
                number = x * y
                Try
                    Lockers(number) = DoLocker(Lockers(number))
                Catch ex As Exception
                End Try
            Next
        Next
        Dim openlocker As Integer = 0
        For z = 0 To LockerNumber - 1
            If Lockers(z) = True Then openlocker = openlocker + 1
        Next
        Console.WriteLine(openlocker.ToString)
        Console.Read()
    End Sub

    Function DoLocker(ByVal Locker As Boolean)
        If Locker = True Then Return False
        If Locker = False Then Return True
    End Function

It's in VB.net and it's pretty basic, but it works :D (I think)

The LockerNumber variable at the top is how many people/lockers there are.
 
Last edited:
Back
Top