Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Help in generating Ulam numbers

I want to generate a list of Ulam numbers (defined by Wikipedia as "a member of an integer sequence devised by and named after Stanislaw Ulam, who introduced it in 1964. The standard Ulam sequence ... starts with U_1 = 1 and U_2 = 2. Then for n > 2, U_n is defined to be the smallest integer that is the sum of two distinct earlier terms in exactly one way and larger than all earlier terms." The code I've written doesn't work. I don't know why I get an "IndexError: list index out of range" (at line 8).

ulam=[1,2,3,4] k=4 while k<10: count=0 for x in range(0,k): for y in range(0,k): if ulam[x]<ulam[y]: if="" ulam[x]+ulam[y]="=ulam[k-1]+1:" count+="1" if="" count="=1:" ulam.append(ulam[k-1]+1)="" k+="1" print="" ulam<="" p="">

Help in generating Ulam numbers

I want to generate a list of Ulam numbers (defined by Wikipedia as "a member of an integer sequence devised by and named after Stanislaw Ulam, who introduced it in 1964. The standard Ulam sequence ... starts with U_1 = 1 and U_2 = 2. Then for n > 2, U_n is defined to be the smallest integer that is the sum of two distinct earlier terms in exactly one way and larger than all earlier terms." The code I've written doesn't work. I don't know why I get an "IndexError: list index out of range" (at line 8).8). Unfortunately, the indenting and line breaks don't seem to show up in the preview.

ulam=[1,2,3,4] k=4 while k<10: count=0 for x in range(0,k): for y in range(0,k): if ulam[x]<ulam[y]: if="" ulam[x]+ulam[y]="=ulam[k-1]+1:" count+="1" if="" count="=1:" ulam.append(ulam[k-1]+1)="" k+="1" print="" ulam<="" p="">

Help in generating Ulam numbers

I want to generate a list of Ulam numbers (defined numbers, with an Ulam number being defined by Wikipedia as "a member of an integer sequence devised by and named after Stanislaw Ulam, who introduced it in 1964. The standard Ulam sequence ... that starts with U_1 = 1 and U_2 = 2. Then for n > 2, U_n is defined to be the smallest integer that is the sum of two distinct earlier terms in exactly one way and larger than all earlier terms." The code I've written doesn't work. I don't know why I get an "IndexError: list index out of range" (at line 8). Unfortunately, the indenting and line breaks don't seem work but there's insufficient room here to show up in the preview.post.

ulam=[1,2,3,4] k=4 while k<10: count=0 for x in range(0,k): for y in range(0,k): if ulam[x]<ulam[y]: if="" ulam[x]+ulam[y]="=ulam[k-1]+1:" count+="1" if="" count="=1:" ulam.append(ulam[k-1]+1)="" k+="1" print="" ulam<="" p="">