# Math quiz

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

1. ### jazzcModeratorStaff MemberModeratorJr. VIP

Joined:
Jan 27, 2009
Messages:
2,519
10,566
Occupation:
Full-time Knitter
Location:
Buenos Aires
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

Winners so far (sorted alphabetically)

healzer
ionica21
JFoulds
Junkfood00
qrazy
phracktl
SmartMan
tacopalypse
45415

Congratulations to all!

• Thanks x 6
Last edited: Mar 6, 2013
2. ### qrazySenior Member

Joined:
Mar 19, 2012
Messages:
1,115
1,721
Location:
Banana Republic
A) 0

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

• Thanks x 1
3. ### JFouldsPower Member

Joined:
Apr 22, 2011
Messages:
538
481
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 x 2
4. ### jazzcModeratorStaff MemberModeratorJr. VIP

Joined:
Jan 27, 2009
Messages:
2,519
10,566
Occupation:
Full-time Knitter
Location:
Buenos Aires
:clap2:
Fixed, thanks

5. ### qrazySenior Member

Joined:
Mar 19, 2012
Messages:
1,115
1,721
Location:
Banana Republic
B) it's 4

• Thanks x 2
6. ### terebiJr. VIPJr. VIPPremium Member

Joined:
Apr 11, 2011
Messages:
349
93
a) 0

It took me about 2 mins of thinking to "get it".

• Thanks x 1
7. ### jazzcModeratorStaff MemberModeratorJr. VIP

Joined:
Jan 27, 2009
Messages:
2,519
10,566
Occupation:
Full-time Knitter
Location:
Buenos Aires
Why?

JFoulds pm'd his explanation btw.

8. ### qrazySenior Member

Joined:
Mar 19, 2012
Messages:
1,115
1,721
Location:
Banana Republic
PMd the explanation

• Thanks x 1
9. ### jazzcModeratorStaff MemberModeratorJr. VIP

Joined:
Jan 27, 2009
Messages:
2,519
10,566
Occupation:
Full-time Knitter
Location:
Buenos Aires
JFoulds & qrazy are the winners so far! Congratulations guys!

Keep the responses coming!

10. ### Junkfood00Elite Member

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

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 x 3
11. ### jazzcModeratorStaff MemberModeratorJr. VIP

Joined:
Jan 27, 2009
Messages:
2,519
10,566
Occupation:
Full-time Knitter
Location:
Buenos Aires
Thanks for the program, it may be useful to people.

Looking forward to your mathematical explanation

12. ### Junkfood00Elite Member

Joined:
Sep 13, 2011
Messages:
1,949
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. ### qrazySenior Member

Joined:
Mar 19, 2012
Messages:
1,115
1,721
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 x 1
14. ### jazzcModeratorStaff MemberModeratorJr. VIP

Joined:
Jan 27, 2009
Messages:
2,519
10,566
Occupation:
Full-time Knitter
Location:
Buenos Aires
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 x 1
15. ### SmartManBANNEDBANNED

Joined:
Jul 25, 2012
Messages:
673
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 x 2
16. ### jazzcModeratorStaff MemberModeratorJr. VIP

Joined:
Jan 27, 2009
Messages:
2,519
10,566
Occupation:
Full-time Knitter
Location:
Buenos Aires
@SmartMan: PM me the explanation

17. ### jazzcModeratorStaff MemberModeratorJr. VIP

Joined:
Jan 27, 2009
Messages:
2,519
10,566
Occupation:
Full-time Knitter
Location:
Buenos Aires
Updated the OP, thanks to all the participants!

• Thanks x 2
18. ### ja1mynSenior Member

Joined:
Feb 3, 2012
Messages:
815
305
Damn I suck at math.

19. ### ionica21Registered Member

Joined:
Apr 14, 2010
Messages:
51
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
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)
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 (I think)

The LockerNumber variable at the top is how many people/lockers there are.

• Thanks x 2
Last edited: Mar 4, 2013

Joined:
Jan 12, 2012
Messages:
547