Vous êtes sur la page 1sur 2

Shahd Sherif

Discrete Math
900140569
Report on Project #4
My Observations:

1. Every set>1 is composed of {} and the previous set. So for example the set 2 will
include {} and the set 1. The set one will include just 0 since it is not > 1.
2. The second observation is that the number of characters in the set is always a power
of 2. Specifically: 2 setnumber-1. So given the length, the set can be achieved by taking
log to the base 2.
3. Any set that the user inputs must be greater than, or equal to in length to whatever set
it actually is.

Thus, in order to find out if an inputted set is one of the natural numbers, it must be compared
with the most likely natural number that it could be. And if every element in the likely natural
number exists in it, at least once, then it is equal to that natural number.

My Approach:

So how I went about solving this problem is, inputting the set. Generating the length, taking
its appropriate log to the base 2, and comparing the natural number which is the floor of that
result. For example, if the user enters a set of length 22, the floor of the log is 4. So I would
need to check if every element in 4 is found at least once in the inputted set. Since of course
there can be repetitions, I would need to check 4 and 3 and 2 and 1 in order to be sure. This is
all built on my observations in the first part.

My Code:
So in order to implement my approach, I needed to be able to produce the set of natural
numbers. One way is to write them all by hand and save them in a data file for comparison,
and then go on with the steps I described in the second part, but Im sure that wouldnt be the
best idea. What I actually did is, I made a function that would return to me the set of the
number I entered. For example, if I send 0, I will receive {}, if I send 1 I will receive {{}},
etc. This function works because of another set of observations I made:
1. If we remove the first { and, the last } of the set n, we get the first n elements of the
set n+1. The last element in n+1, is the set n itself.
2. The base element is {}.
3. Every set is composed of: { + the contents + }, where the contents in n+1 is: n-{} + n.
4. the contents can be acquired by repeating the following process floor (log2((length
of input))), or just n, times.
5. The process is, starting n =1 for example, starting with the base element, {}, we
remove the opening and closing braces, and then returning. {+ base element-{} + base
element+}. Since n=1, this will repeat 1 times.
So now I have a way of generating the nth natural number. All I need to do now, is input a
set, count the number of elements, take the floor of the log to the base 2, and check that
number, and all of the ones before it until the base element. By checking I mean, make
sure that every element in the natural number that my function returned exists in the
inputted number. If it is a valid natural number (regardless of order, or repetition like the
question asked), it will be one of them. Note: I only considered the case of repetition or
order, because it was not specified to consider anything else in the question.

Vous aimerez peut-être aussi