On Mon, Apr 5, 2010 at 12:58 PM, Dana Ernst <[email protected]> wrote:
> This does help.  BTW, above, I meant to write (swap order of k and j):
>
> for k in range(1,40):
>     for j in range(16):
>         if gcd(k,40) == 1:
>             print (U(k))^j
>
> Is there a way to insert a character after each (U(k))^16, so that it is
> obvious where the loop (correct terminology?) starts over?  Also, feel free
> to offer a different approach to this altogether.

This uses a few more constructs; for example, the continue statement
will cause it to immediately go to the next value in the loop.  You
can also iterate directly over the elements of U.  The single print
statement will print a new line (the comma at the end suppresses the
new line).

U = Integers(40)
for k in U:
    if gcd(k,40) != 1:
        continue
    else:
        print k, ":",
    for j in range(16):
        print k^j,
    print


1 : 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 : 1 3 9 27 1 3 9 27 1 3 9 27 1 3 9 27
7 : 1 7 9 23 1 7 9 23 1 7 9 23 1 7 9 23
9 : 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9
11 : 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11
13 : 1 13 9 37 1 13 9 37 1 13 9 37 1 13 9 37
17 : 1 17 9 33 1 17 9 33 1 17 9 33 1 17 9 33
19 : 1 19 1 19 1 19 1 19 1 19 1 19 1 19 1 19
21 : 1 21 1 21 1 21 1 21 1 21 1 21 1 21 1 21
23 : 1 23 9 7 1 23 9 7 1 23 9 7 1 23 9 7
27 : 1 27 9 3 1 27 9 3 1 27 9 3 1 27 9 3
29 : 1 29 1 29 1 29 1 29 1 29 1 29 1 29 1 29
31 : 1 31 1 31 1 31 1 31 1 31 1 31 1 31 1 31
33 : 1 33 9 17 1 33 9 17 1 33 9 17 1 33 9 17
37 : 1 37 9 13 1 37 9 13 1 37 9 13 1 37 9 13
39 : 1 39 1 39 1 39 1 39 1 39 1 39 1 39 1 39


--Mike

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using "remove me" as the subject.

Reply via email to