Download // BRUTE FORCE AND PATTERN RECOGNITION There are 1,000

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
// BRUTE FORCE AND PATTERN RECOGNITION
There are 1, 000 students and 1, 000 lockers, numbered from 1 to 1, 000 , on one side of
a long hallway. The first person went down the hall and opened every locker. The
second person went down the hall and changed every second locker (i.e. closed every
† third
† locker
second locker). The†third person went†down the hall and changed every
(i.e. closed each open third locker, and opened each closed third locker). Similarly, the
fourth person changed every fourth locker, the fifth changed every fifth locker, and so
on…. After the 1, 000 th person changed the 1, 000 th locker door, which lockers are
open?
Problems like this one can †
be intractable to those who fail†to approach the problem in a
reasonable way. Certainly, reason varies and I am not claiming that my approach is
better than anyone else’s. I can recall when I was given a very similar problem and
what approach I used to solve it. I felt the problem was better analyzed by a computer
than by meticulously going through 1, 000 lockers with 1, 000 students, or even a
smaller, more manageable subset. As in the past, I felt computers were very good at
brute force analysis and producing results that could be inspected for patterns. So off I
†
went to write the following C++ source code: †
#include <iostream> // for cout()
using namespace std;
int main(void)
{
// locker[1] to locker[1000]
int locker[1001];
// simple counter variables
int student, j;
// initialze all lockers to closed, state zero
for ( j = 1 ; j <= 1000 ; j++ )
locker[j] = 0;
// now start the problem
// these are the 1,000 students
for ( student = 1 ; student <= 1000 ; student++ )
// these are the lockers
for ( j = student ; j <= 1000 ; j++ )
// checking for divisor
if ( ( j / student ) * student == j )
// change state
locker[j] = !(locker[j]);
for ( j = 1 ; j <= 1000 ; j++)
if( locker[j] == 1)
cout << "Locker " << j << " is open.\n";
}
After compiling and running this C++ source code, the output is as follows:
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
1 is open.
4 is open.
9 is open.
16 is open.
25 is open.
36 is open.
49 is open.
64 is open.
PAGE 10
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
Locker
DETERMINISTIC UNCERTAINTIES
81 is open.
100 is open.
121 is open.
144 is open.
169 is open.
196 is open.
225 is open.
256 is open.
289 is open.
324 is open.
361 is open.
400 is open.
441 is open.
484 is open.
529 is open.
576 is open.
625 is open.
676 is open.
729 is open.
784 is open.
841 is open.
900 is open.
961 is open.
It is quite clear that the output involves a sequence of perfect squares from 1 to 961.
Aha! Using a computer simulation of a physical problem that was difficult or
impossible to replicate physically gave insight regarding the solution. There must be
something here! Of course, we need to know why this happened, and knowing what to †
look for often helps in understanding the underlying events. However, why did only
perfect squares come up? Knowing the ‘answer,’ not the elegance in finding the
pattern, was an artifact of the code. Every perfect square from 1 to 961 came up — so
what? The tedious part of the work is done, all without the paper and pencil nonsense.
Real thinking should never be tedious.
† †
The real work is about to begin, now after knowing the sequence of events and
knowing the pattern that those events produce, but why did such a clean result appear?
There must be some mathematical theory behind the pattern.
All lockers that remain opened must have been changed an odd number of times.
Lockers that remain closed must have been changed an even number of times. By
looking at a smaller subset of the problem, it is easy to show that the perfect squares
were changed an odd number of times, and the non-perfect squares were changed an
even number of times.
†
PAGE 11
DETERMINISTIC UNCERTAINTIES
Locker
Student
Total
State
Locker No 1
Student No 1
1 student
Odd
Locker No 2
Student No 1, & 2
2 students
Even
Locker No 3
Student No 1, & 3
2 students
Even
Locker No 4
Student No 1, 2, & 4
3 students
Odd
Locker No 5
Student No 1, & 5
2 students
Even
Locker No 6
Student No 1, 2, 3, & 6
4 students
Even
Locker No 7
Student No 1, & 7
2 students
Even
Locker No 8
Student No 1, 2, 4, & 8
4 students
Even
Locker No 9
Student No 1, 3, & 9
3 students
Odd
Locker No 10
Student No 1, 2, 5, & 10
4 students
Even
Locker No 11
Student No 1, & 11
2 students
Even
Locker No 12
Student No 1, 2, 3, 4, 6, & 12
6 students
Even
Locker No 13
Student No 1, & 13
2 students
Even
Locker No 14
Student No 1, 2, 7, & 14
4 students
Even
Locker No 15
Student No 1, 3, 5, & 15
3 students
Even
Locker No 16
Student No 1, 2, 4, 8, & 16
5 students
Odd
Note: The student numbers are divisors of the locker numbers. So we need to count the
number of divisors of each locker number to determine how many changes
(open/close) have been made.
The pattern is becoming evident. All non-zero natural numbers always have one and
themselves as divisors. In addition, non prime numbers have other divisors a well.
Perfect squares, when in prime factored form, will always have an even number of
factors, and all their factors will occur in pairs. For example, 144 has the prime
factored form (2 ¥ 2) ¥ (2 ¥ 2) ¥ ( 3¥ 3) . Non perfect squares when in prime factored
form may have either an odd or even number of factors. However, a non perfect
† prime
square’s prime factors will not all occur in pairs. For example 132 has the
† ) , certainly an even number of prime factors, but they do
factored form (2 ¥ 2) ¥ ( 3¥11
not occur in pairs, hence they are not perfect squares. Therefore an essential difference.
† task of counting the number of divisors of a prime number
Now we are left with the
raised to an integral power, p n , with the above in mind. The number of divisors of p n ,
†
†
PAGE 12
DETERMINISTIC UNCERTAINTIES
where p is prime and n is a natural number, is n +1. By the multiplication principle,
the number of divisors of a composite number p1n1 ⋅ p2n2 ⋅ p3n3 ⋅ p4n4 ⋅L⋅ pmnm , composed of
m
m primes is
(n +1) ,
’
†
i
i=i
which is the mathematical short hand for the product
†
†
3
5
2
(n1 +1) ⋅ (n2 +1) ⋅ (n3 +1) ⋅ (n4 +1) ⋅L⋅ (nm +1) . For example
† 254, 205, 875 = 5 ⋅ 7 ⋅11
should have
† ( 3+1) ⋅ (5 +1) ⋅ (2 +1) = 72 divisors. Here are the seventy-two divisors of
254, 205, 875 :
†
†
†
1, 5, 7, 11, 25, 35, 49, 55, 77, 121, 125, 175, 245, 275, 343, 385, 539, 605, 847,
† 1925, 2401, 2695, 3025, 3773, 4235, 5929, 6125, 8575, 9625,
875, 1225, 1375, 1715,
12005, 13475, 15125, 16807, 18865, 21175, 26411, 29645, 41503, 42875, 60025, 67375,
84035,†94325, 105875, 132055, 148225, 184877, 207515, 290521, 300125, 420175,
471625, 660275, 741125, 924385, 1037575, 1452605, 2033647, 2100875, 3301375,
4621925, 5187875, 7263025, 10168235, 23109625, 36315125, 50841175, 254205875.
m
2n1
1
Perfect squares, are of the form p
⋅p
2n2
2
⋅p
2n3
3
⋅p
2n 4
4
⋅L⋅ p
2nm
m
, have
’ (2n +1)
i
i=i
possible divisors. Every factor in the product is an odd number and hence not divisible
by two. Non perfect squares do not display
this property. For example
†
2
2
6
†
should
have
divisors. Here are the twenty2
⋅1+1
⋅
2
⋅
3+1
=
21
54 = 2, 916 = 2 ⋅ 3
(
)(
)
one divisors of 2, 916 :
1, 2, 3,
† 4, 6, 9, 12, 18, 27, 36, 54, 81,
† 108, 162, 243, 324, 486, 729, 972, 1458,
2916
†