1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Math quiz

Discussion in 'BlackHat Lounge' started by jazzc, Mar 3, 2013.

  1. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    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!
     
    • Thanks Thanks x 6
    Last edited: Mar 6, 2013
  2. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,111
    Likes Received:
    1,712
    Location:
    Banana Republic
    A) 0


    for question 2... the series you mentioned 3,6,9,12,16,20 is right or a typo??
     
    • Thanks Thanks x 1
  3. JFoulds

    JFoulds Power Member

    Joined:
    Apr 22, 2011
    Messages:
    538
    Likes Received:
    480
    Occupation:
    Genius billionaire playboy philanthropist
    Skipped the easy question.
    Hard question: 4 lockers?

    I'll PM you the formula, don't want to ruin it.
     
    • Thanks Thanks x 2
  4. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    :clap2:
    Fixed, thanks :)
     
  5. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,111
    Likes Received:
    1,712
    Location:
    Banana Republic
    B) it's 4

     
    • Thanks Thanks x 2
  6. terebi

    terebi Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 11, 2011
    Messages:
    337
    Likes Received:
    62
    a) 0

    It took me about 2 mins of thinking to "get it". :)
     
    • Thanks Thanks x 1
  7. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    Why?

    JFoulds pm'd his explanation btw.
     
  8. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,111
    Likes Received:
    1,712
    Location:
    Banana Republic
    PMd the explanation:)

     
    • Thanks Thanks x 1
  9. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    JFoulds & qrazy are the winners so far! Congratulations guys!

    Keep the responses coming! :)
     
  10. Junkfood00

    Junkfood00 Elite Member

    Joined:
    Sep 13, 2011
    Messages:
    1,949
    Likes Received:
    1,336
    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;
    
    }
    
     
    • Thanks Thanks x 3
  11. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    Thanks for the program, it may be useful to people.

    Looking forward to your mathematical explanation :)
     
  12. Junkfood00

    Junkfood00 Elite Member

    Joined:
    Sep 13, 2011
    Messages:
    1,949
    Likes Received:
    1,336
    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.
     
  13. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,111
    Likes Received:
    1,712
    Location:
    Banana Republic
    Nice one. If you had thought of the problem mathematically(with numbers), you could've avoided the extra 'for' loops in the code.....


     
    • Thanks Thanks x 1
  14. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    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 :)
     
    • Thanks Thanks x 1
  15. SmartMan

    SmartMan BANNED BANNED

    Joined:
    Jul 25, 2012
    Messages:
    673
    Likes Received:
    1,244
    The total number of lockers left open for 1 billion lockers and people is 31622. Formula is still the same that you use for Quiz #2.
     
    • Thanks Thanks x 2
  16. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    @SmartMan: PM me the explanation :)
     
  17. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    Updated the OP, thanks to all the participants!
     
    • Thanks Thanks x 2
  18. ja1myn

    ja1myn Senior Member

    Joined:
    Feb 3, 2012
    Messages:
    811
    Likes Received:
    300
    Damn I suck at math.
     
  19. ionica21

    ionica21 Registered Member

    Joined:
    Apr 14, 2010
    Messages:
    51
    Likes Received:
    15
    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.
     
    • Thanks Thanks x 2
    Last edited: Mar 4, 2013
  20. Seankearns

    Seankearns Jr. VIP Jr. VIP Premium Member

    Joined:
    Jan 12, 2012
    Messages:
    547
    Likes Received:
    365
    Location:
    Canada
    You almost got me to do your math homework. Well played jazzc. Well played.
     
    • Thanks Thanks x 2