Step 1: Understanding the problem
Given two drawers, left and right with the left drawer holding n pennies(n being a positive integer), what combinations of pennies in either drawer can be reached using the following operations?
Left:If there are an even number of penny in the left drawer, half may be transferred to the right drawer. Otherwise the pennies in that drawer must be left alone.
Right:If there are an even number of penny in the right drawer, half may be transferred to the left drawer. Otherwise the pennies in that drawer must be left alone.
In this problem solving episode the unknown is the number of integers than can be found by executing the above functions on the drawers with the left containing n pennies.
Step 2: Devising a Plan
My first approach to this problem was to utilize brute force so I could observe a pattern.
I decided to use tree diagrams as I felt that the problem fit the criteria of a tree data structure.
Step 3: Carrying Out a Plan:
After drawing these tree diagrams I compiled a table.
N
|
Numbers found
|
Total number not including 0
|
1
|
0,1
|
1
|
2
|
0,1,2
|
2
|
3
|
0,3
|
1
|
4
|
0,1,2,3,4
|
4
|
5
|
0,5
|
1
|
6
|
0,3,6
|
2
|
7
|
0,7
|
1
|
8
|
0,1,2,3,4,5,6,7,8
|
8
|
9
|
0,9
|
1
|
10
|
0,5,10
|
2
|
11
|
0,11
|
1
|
12
|
0,3,6,9,12
|
4
|
Values of n that are of base 2^x produce all integers in their range([0,...n])
Odd numbers only produced themselves as they are not divisible by 2.
Even numbers with prime factors other than 2 produced 2 numbers, themselves and their other prime factor.
I still could not find a pattern so I decided to automate by production of further results using Python.
def penny_piles(L):
numbers_found = [L[0],L[1]]
if L[0] % 2 == 0:
left= L[0] // 2
right = L[1] + left
numbers_found += penny_piles([left, right])
if L[1] % 2 == 0 and L[1] != 0:
right = L[1] // 2
left = L[0] + right
numbers_found += penny_piles([left, right])
elif L[0] % 2 == 1 or L[1] % 2 == 1:
return L
numbers_found = remove_duplicates(numbers_found)
return numbers_found
def remove_duplicates(L):
L.sort()
for x in L:
if L.count(x) > 1:
y = L.count(x)
while y > 1:
L.remove(x)
y -= 1
return L
As confirmed by graph, numbers n that are of 2^x produce n numbers and odd numbers produced 1 number.
As for even numbers; numbers that are even and only have the prime factors 2 and another prime produce only 2 numbers.
However I was not able to produce a pattern for even numbers.
Step 4: Looking back
I was not able to create an algorithm for predicting the
As for even numbers; numbers that are even and only have the prime factors 2 and another prime produce only 2 numbers.
However I was not able to produce a pattern for even numbers.
Step 4: Looking back
I was not able to create an algorithm for predicting the


No comments:
Post a Comment