You are on page 1of 12

15-251 Assignment 7

Write your name here!


your-andrew-id@andrew.cmu.edu
ABCDEFG
March 18, 2011
0: Bunny Duck and the Pile of Pancakes
Claim: An upperbound on the number of rounds it takes Bunny to eat n pancakes is 2log
2
n +1
Lemma: If there are an odd number of pancakes remaining, Bunny will remove an odd number
of pancakes, resulting in an even stack after removal.
Proof of Lemma: Suppose there are k pancakes remaining where k is odd. The prime
factorization of k is of the form 2
0
P
n
1
1
P
n
2
2
P
n
3
3
P
n
m
m
where all the P
i
s are odd. For
each P
i
, bunny will remove the pancakes of indices P
i
, 2P
i
, . . . , (
k
P
i
1)P
i
not including
the k
th
pancake. Furthermore, since
k
P
i
is odd, Bunny removes an even number of
multiples of P
i
for each 1 i m (still not including the k
th
pancake). However, there
may exist P
i
, P
j
i = j such that the removed multiples of P
i
overlap with the removed
multiples of P
j
.
Sub-lemma: Given k is odd, the size intersection of the removed multiples (not includ-
ing pancake-k) of any 2 odd factors of k, (call them p, q) is even.
Proof of Sub-lemma: Since the least common multiple of any two odd numbers p, q,
is odd (since neither p nor q has a 2 in their prime factorization, the LCM does not
include a 2 in its own prime factorization), the removed multiples of lcm(p, q) must
be even (from above Lemma).
By the above sub-lemma, since the intersection of the removed multiples of any two
odd factors of k is even, it follows that Bunny will always removed an [even number] of
pancakes plus the k
th
pancake if k is odd. Thus, an odd total is removed, necessarily
leaving Bunny with an even number of pancakes.
Proof of Claim: Any round in which Bunny has k pancakes can be divided into 2 cases:
k is even: Since Bunny has an even number of pancakes, 2 is a factor of k. Furthermore,
since there are exactly
k
2
even pancakes,
k
2
pancakes will be removed during this case.
k is odd : Since k is odd, bunny will remove an odd number of pancakes (by Lemma) to
result in an even number of remaining pancakes. For purposes of generality, consider
this step to remove 0 pancakes.
Since bunny cannot yield two odd piles in a row, at least half the rounds include even piles.
Since even piles reduce the entire pile by half, (and since you can only reduce a number n
in half by log
2
n times), Bunny can always eat the entire pile in at most 2log
2
n + 1 rounds
(where the +1 represents the nal pancake).
1
1: Bunny Duck and the Chamber of Music
Let X be the random variable that counts the number of unique songs played before captcha
face.
Let X
i
(0 i 999) be the random variable such that
X
i
=

i if i unique songs are played before captcha face


0 otherwise
Since the X
i
s correspond to disjoint partitions of all possible outcomes, X =

999
k=0
X
k
.
Claim: E[X] =
999
2
Lemma: Bunnys duckPod will play all 1000 unique songs in a nite number of plays
Proof: Since the songs are randomly selected after each play, each song has a
999
1000
of not
being played each round. Thus, the probability that an arbitrary song is not played after
round k is

999
1000

k
. As k , this value approaches 0 (it represents a geometric series
with a ratio of < 1). Since there are a nite number of songs, the probability that there
exists a song that has not been played after k rounds also approaches zero as k .
Thus, all 1000 songs will eventually be played.
Proof of Claim: Consider the following scenario:
Allow Bunnys duckPod to continuously play songs until all 1000 songs (including captcha
face) are played (this will happen by the above Lemma).
Creat a list of the order of appearance of the 1000 songs. Ex. If the sequence of songs played
is (3,3,1,3,2), then the list of order of apppearance is (3,1,2).
By the selection process of Bunnys duckPod, the resulting list is a random permutation
of [1000] (as there is no song-bias). Thus, there probability that captch face is the i
th
song is
1
1000
(for all 1 i 1000). For each i, [captcha face being the i
th
song on the list]
implies that (i 1) unique songs were played before captcha face. Thus, [captcha face
being the i
th
song on the list] coincides with the random variable X
i1
. Thus, we nd that
P[X
i
= i] =
1
1000
for all 0 i 999.
By denition of expected value, E[X
i
] =

k=0
kP[X
i
= k]. Since each X
i
can take on only one
possible non-negative value, we see that E[X
i
] = (i)P[X
i
= i]. From above, P[X
i
= i] =
1
1000
for all i, thus E[X
i
] =
i
1000
for all i. We wish to nd E[X] which equals E[

999
k=0
X
k
]. By
linearity of expectation, this is equal to
999

k=0
E[X
k
] =
999

k=0
k
1000
=
1
1000
999

k=0
k
=
1
1000
(999 + 0)(1000)
2
=
999
2
2: Bunny Duck and the Chamberer of Musicer
Call the number of times Bunny will hear the same artist play three songs in a row the number
of repeats
3
.
Let the random variable X count the number of repeats
3
.
Label the sequence of played songs with indices from 1 to 1000.
Claim: Given Bunnys conguration,
E[X] = (998)(100)

10
3

(3!)

997!
1000!

= (998)(100)

10
3

(6)

1
1000

1
999

1
998

=
8
111
Proof: Let X
i
be a random variable such that:
X
i
=

1 if the i
th
, (i + 1)
th
, and (i + 2)
th
song are of the same artist
0 otherwise
In other words, X
i
is 1 if the i
th
consecutive triplet contains a repeat
3
and 0 otherwise. Since
(i + 2) 1000, we see that 1 i 998. Thus, there are 998 consecutive triplets, each of which
corresponds to some random variable X
i
. Since E[X
i
] =

k=0
kP[X
i
= k] and since 1 is the only
positive value any X
i
can take, we see that E[X
i
] = (1)P[X
i
= 1] = P[X
i
= 1] for all X
i
. In other
words, the probability that the i
th
triplet contains a repeat
3
equals the expected value of X
i
.
Consider some arbitrary consecutive triplet of songs (call it the i
th
triplet). Since the sequence of
songs played on Bunnys duckPod is, by denition, a random permutation of [1000], P[X
i
= 1] =
[number of permutations in which the i
th
triplet contains a repeat
3
(valid permutations)]
divided by
[total number of permutations].
Total permutations: Clearly, the number of permutations of [1000] is 1000!
Total valid permutations: Consider the quality of a valid permutation:
The i
th
, (i + 1)
th
, and (i + 2)
th
song are all of the same artist (and there are 100 artists
total)
The 3 songs (mentioned above) are uniquely ordered (since all songs are distinct)
Because of the above conditions, we can count the number of valid permutations as follows:
Pick the artist to represent in the triplet (there are 100 ways to do this)
Pick 3 songs of the artist to repeat
3
(since each artists has 10 songs, there are

10
3

ways
to do this)
Order the 3 songs in some order (this is equal to the number of premutations of [3] =
3!)
The remaining 997 songs can be ordered arbitrarily/freely (this is equal to the number
of permutations of [997] = 997!)
Combining these terms by the combinatorial product rule, we see that there are (100)

10
3

(3!)(997!)
valid permutations. Dividing by total permutations, we get (100)

10
3

(3!)

997!
1000!

. Thus,
E[X
i
] = P[X
i
= 1] = (100)

10
3

(3!)

997!
1000!

for all 1 i 998.


By our construction of X
i
, E[X] = E[

998
k=1
X
k
]. By linearity of expectation,
E[X] =

998
k=1
E[X
k
]. Substituting our calculated value for X
i
(from above), E[X] =

998
k=1
(100)

10
3

(3!)

997!
1000!

= (998)(100)

10
3

(3!)

997!
1000!

, giving the desired result.


3: Bunny Duck and the Row of Hats (Part A)
Let X be the random variable that counts the number of ways Bunny must apply the Hat Sorter
to get his favorite hat to return to its orginal position.
Let X
i
be the random variable such that
X
i
=

i if i applications are required


0 otherwise
Since no cycles of size 1 are allowed, the possible sizes of cycles are 1, 2, 3, . . . , (n2), n. Note that
n 1 is not an allowed size as this would imply that the remaining index is on its own cycle.
By denition of expected value, E[X
i
] =

k=0
kP[X
i
= k] Since each X
i
can take on only 1 possible
non-negative value, E[X
i
] = (i)P[X
i
= i].
Since each X
i
represents disjoint partitions of all possible outcomes, X = X
2
+X
3
+ +X
n2
+X
n
.
E[X] = E[X
2
+ X
3
+ + X
n2
+ X
n
]
= E[X
2
] + E[X
3
] + + E[X
n2
] + E[X
n
] (by linearity of expectation)
Label the slots of the Hat Sorter by the numbers (1,2,3, ..., n)
Claim: E[X] =
n
2
Proof: Let the Hat Sorters algorithm be represented by a derangement, , of n such that (i) =
the index the i
th
hat is sent to per application ((i) = i
i
). WLOG, let Bunnys favorite hat
(call it HH) be at index 1. Since (1) = 1, one application of the Sorter will move HH to
some index j = i. The probability that 2 applications of the sorter is required to return HH
to index 1 (denoted by P[X
2
= 2]) is given by P[(j) = 1]. Since the Hat Sorters algorithm
was randomly generated and since (j) can take on (n1) possible values (every index except
itself) each with equal probability. Thus, P[(j) = 1] =
1
n1
= P[X
2
= 2] = E[X
2
] (from
above). For each possible cycle length k, HH must avoid index 1 for k 1 rounds and
land on index 1 on the k
th
round. With each successive round, the number of valid spaces
HH may land on decreases by 1 and the number of possible spaces HH may land on also
decreases by 1 (the index from which it had came is no longer a possible). The probability of
HH avoiding index 1 for k 1 rounds is thus given by (for k 2)

n 2
n 1

n 3
n 2

n k + 1
n k + 2

=
(n 2)!
(n k)!
(n k + 1)!
(n 1)!
On the k
th
round, HH needs to land on index 1 out of (n k + 1) possible locations, thus
P[X
k
= k] =

(n k 1)
(n 1)

1
n k + 1

=
1
n 1
For all valid cycle-lengths k
From above, we see that
E[X] =
n
n 1
+
n2

i=2
(i)
1
n 1
=
n
n 1
+
1
n 1
((n 2) + 2)(n 3)
2
=
2n + (n)(n 3)
2(n 1)
=
n(n 1)
2(n 1)
=
n
2
4: Bunny Duck and the Row of Hats (Part B)
5: Bunny Ducks Big Beach Challenge
Lemma 1: 10
k
1(mod 9) for all k 0
Proof by induciton:
Inductive hypothesis Suppose 10
k
1 (mod 9) for some k
Base case: k = 0
10
0
= 1 which is congruent 1 (mod 9)
Inductive step: Suppose the I.H. for some k. (10) 10
k
(10)1 (mod 9). Since (10) 10
k
=
10
k+1
and since 10 1 (mod 9), it follows that 10
k+1
1 (mod 9).
Lemma 2: d 10
k
d (mod 9) for all d 0.
Since 10
k
1 (mod 9) for k 0 (by Lemma 1), it follows easily that multiplying any number
d to both sides yields: d 10
k
(d)(1) d (mod 9).
Lemma 3: The [sum of the digits of any base-10 number] [the same number] (mod 9).
Let some arbitrary number k be denoted by the base-10 representation d
n
d
n1
. . . d
1
d
0
. By
denition, the value of this number is computed by

n
j=0
d
j
10
j
. By Lemma 2, this is congruent
to

n
j=0
d
j

(mod 9), however, this is exactly the sum of the digits of k.


Proof: The [sum of the digits] of any number formed by the concatenation of the numbers 1 to
15251 is congruent to [the sum of the numbers 1 to 15251] (mod 9) by Lemma 3.

15251
k=1
k

=
(15251+1)(15251)
2
=
1525215251
2
. Since the digits of 15252 sum to 15, 15252 6 (mod 9). Since
the digits of 15251 sum to 14, 15251 5 (mod 9). Thus
1525215251
2

65
2
15 6 (mod
9). Since the sum of the digits of Bunnys number is necessarily congruent 6 (mod 9), any
number Bunny writes is congruent 6 (mod 9).
Let d be a possible number Bunny writes. We want to show that n
m
(m 2) cannot equal
d for all possible d. Since d 6 (mod 9), d can be expressed in the for 9k + 6. Since d can
also be expressed in the form 3(3k + 2), 3|d. Assume that n
m
= d. The prime factorization
of n must contain a 3, otherwise 3 cannot be a factor of n
m
. Thus, we can express n as 3w
for some w. Then n
m
= (3w)
m
= (3w)
2
(3w)
m2
= 9w
2
(3w)
m2
(recall that m 2). Since 9
is a factor of n, this implies that n 0 (mod 9), contradicting our assumption that n
m
can
equal d.
6: Bunny Duck and the Sorting Rainbow
Part 1: Proof by strong induction on k.
Inductive hypothesis: Assume that (a+b)|(a
n
+b
n
) for all odd n k for some odd k 0.
Base case: k = 1
Since a
1
= a and b
1
= b, clearly (a + b)|(a
1
+ b
1
).
Inductive step: Assume the I.H. for some odd k 0.
Consider (a + b)
k+2
: By binomial theorem, (a + b)
k+2
=

k+2
i=0

k+2
i

a
i
b
k+2i
Extracting the rst and last term, we get (a+b)
k+2
= a
k+2
+b
k+2
+

k+1
i=1

k+2
i

a
i
b
k+2i
Splitting the sum (recall that k + 1 is even),
(a + b)
k+2
= a
k+2
+ b
k+2
+
k+1
2

i=1

k + 2
i

a
i
b
k+2i
+
k+1

i=
k+1
2
+1

k + 2
i

a
i
b
k+2i
Since

k+2
i

k+2
k+21

, we can reverse the order of the second summation to obtain:


(a + b)
k+2
= a
k+2
+ b
k+2
+
k+1
2

i=1

k + 2
i

a
i
b
k+2i
+
k+1
2

i=1

k + 2
i

b
i
a
k+2i
Combining the sum:
(a + b)
k+2
= a
k+2
+ b
k+2
+
k+1
2

i=1

k + 2
i

a
i
b
k+2i
+ b
i
a
k+2i
For each iteration, factor out a
i
b
i
:
(a + b)
k+2
= a
k+2
+ b
k+2
+
k+1
2

i=1

k + 2
i

a
i
b
i
(b
k+22i
+ a
k+22i
)
Note that when i =
k+1
2
, b
k+22i
+ a
k+22i
= b
1
+ a
1
so the exponents of b and a in
b
k+22i
+ a
k+22i
will always be positive. Furthermore, the exponents are always odd:
k is odd so (k + 2 2i) is odd for any integer i.
When i = 1 the summation produces

k+2
i

ab(b
k
+ a
k
). Since k k, we can invoke
the inductive hypothesis on all the terms of the summation. Thus, (a + b) must divide

k+1
2
i=1

k+2
i

a
i
b
i
(b
k+22i
+ a
k+22i
) (let this summation be called c).
We then have (a +b)
k+2
= a
k+2
+b
k+2
+c. Since (a +b)(a +b)
k+1
= (a +b)
k+2
, (a +b)
clearly divides (a + b)
k+2
. By the above equality, (a+b) must divide a
k+2
+ b
k+2
+ c.
Since (a+b) divides c, (a+b) must divide (a
k+2
+b
k+2
+c)c = a
k+2
+b
k+2
, completing
the inductive step.
Part 2: Given k distinct hats and 15251 distinct pancakes, there are k
15251
ways to distrubute the
pancakes among the hats. (k choices for rst pancake, k choices for second pancake, ..., k
cohices for the 15251
th
pancake). Thus, if for each i n Bunny has i hats of some color, the
number of ways to place his pancakes into the hats is the sum of the number of ways to place
his pancakes into each color group. This is given by
n

i=1
n
15251
= 1
15251
+ 2
15251
+ + n
15251
(summing for each color)
Case odd n: We can split the sum as (1) +(2
15251
+n
15251
) +(3
15251
+(n1)
15251
) + +
(

n+1
2

15251
+

n+3
2

15251
)
n

i=1
n
15251
= 1 +
n+1
2

i=2
i
15251
+ (n + 2 i)
15251
Since (i+n+2i) = n+2, it follows from part 1 that n+2 divides

n+1
2
i=2
i
15251
+ (n + 2 i)
15251
However, n+2, cannot divide

n
i=1
n
15251
as it is congruent 1 (mod (n+2)).
Case even n: Split the sum as was done in the odd case
It suces to show that n + 2 does not divide the leftover terms =

n
2

15251
+ 1 =
n
15251
+2
15251
2
15251
=
(2k)
15251
+2
15251
2
15251
=
2
15251
k
15251
+2
15251
2
15251
=
2
15251
(k
15251
+1)
2
15251
= k
15251
+ 1
15251
By
part 1, (k + 1) divides this term, however, since n + 2 = 2k + 2
7: Bunny Duck and the Awesome Party
Let X be the random variable the counts the number of ducks at the party that are not wearing a
hat, and have no friends wearing a hat (call this the number of unhappy ducks).
Claim: E[X] 1000
(
899
63
)
(
1000
63
)
= 1000

899!
(89963)!63!
1000!
(100063)!63!

.97086 < 1
Proof: Index the ducks from 1 to 1000. Let X
i
denote the random variable that equals
X
i
=

1 if duck i is unhappy
0 if duck i is happy
Thus, X =

1000
k=1
X
k
Consider some arbitrary i
th
duck, d
i
. In order for d
i
to be unhappy, he must not be given a
hat and none of his 100 friends must be given hats. For sake of simplicity, lets assume that
d
i
has exactly 100 friends (we will come back to the case of 100 later). Upon distributing
the 63 hats, none of the hats may be given to d
i
and none may be given to any of d
i
s 100
friends. Thus, there are (1000-1-100) = 899 valid recipients for the 63 hats. Since the hats are
given at random, every possible distribution of hats is uniformly likely. Thus, the probability
that the 63 hats are given within the 899 valid recipients is the [number of ways to distribute
63 hats to 899 ducks]/[number of ways to distrubute 63 hats to all 1000 ducks]. This number
is given by
(
899
63
)
(
1000
63
)
Thus, P[X
i
= 1] =
(
899
63
)
(
1000
63
)
. Since E[X
i
] =

k=0
kP[X
i
= k] and since 1 is
the only positive value any X
i
can take, we see that E[X
i
] = (1)
(
899
63
)
(
1000
63
)
=
(
899
63
)
(
1000
63
)
.
Now re-consider the possibility of d
i
having 100 friends. This means that there will be
899 valid recipients for the hats and E[X
i
] will equal
(
k
63
)
(
1000
63
)
where k 899. Since

n
k

increases monotonically with respect to n, we see the k 899 implies that


(
k
63
)
(
1000
63
)

(
899
63
)
(
1000
63
)
.
Thus,
(
899
63
)
(
1000
63
)
serves as an upper bound for each E[X
i
] (1 i 1000).
Recall: X =

1000
k=1
X
k
. By linearity of expectation, E[X] =

1000
k=1
E[X
k
] 1000
(
899
63
)
(
1000
63
)
(since
(
899
63
)
(
1000
63
)
is an upperbound for each E[X
i
], it follows that 1000
(
899
63
)
(
1000
63
)
is an upperbound
for E[X]). By computation by computer, we see that E[X] < 1 as desired.
Since E[X] < 1 and since X can only take on integer values, there must always exist a
way to distribute 63 hats such that all the ducks are happy (regardless of the friendship
graph). This is equivalent to saying that there always exists a conguration which yields no
unhappy ducks. To see this, suppose that all conguration yields at 1 unhappy duck. Since
E[X] =

k=0
kP[X = k], subtracting the zero term (since its assumed impossible) yields

k=1
kP[X = k]. Since

k=1
P[X = k] = 1,

k=1
kP[X = k] 1 which contradicts our
conclusion.

You might also like