[Tutor] new to prog. question

Alfred Milgrom fredm@smartypantsco.com
Tue Mar 25 23:35:02 2003


Hi:

Your question is not exactly clear.

You have created a list of powers of 2, and you want to know if a given 
number is the sum of numbers in that list.
I assume that you know that any number (within the given range) can be 
expressed as the sum of powers of 2.

For example 13 = 8 + 4 + 1

So can you please explain your question better?
Do you want to find out if a given number is the sum of only 2 numbers in 
the list OR do you want to find out which powers of 2 add up to the given 
number?

Alfred Milgrom

At 01:08 AM 26/03/03 +0000, riex@ligbr.com.br wrote:

>Hi tutor.
>I've a simple question.
>I create a list containing numbers. list1=[1,2,4,8,16,32,64,128,512]
># which is 2**0 ...2**10
>If I wanted to find if a given number, 12 for example, is
>in the list would be easy. But, how about if x+y in the list equals
>the number (12) ?
>So, 8 + 4 for example.
>Maybe I am just going the wrong way here, and there is a easier way to do 
>this.
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>