
Introduction to Sage 405
....: f = [q for q,e in factor(p-1)]
....: print p, f[-1]
....:
3 2
5 2
7 3
11 5
13 3
17 2
19 3
23 11
29 7
The next program lists subsets:
sage: for s in subsets([1,2,3]):
....: print s
....:
[]
[1]
[2]
[1, 2]
[3]
[1, 3]
[2, 3]
[1, 2, 3]
The while loop continues looping until a particular criterion is satisfied. Here
is an example: finding the smallest power of two that contains all ten digits
(such a number is called pandigital). Start with noting that if n is any integer,
then
set([x for x in str(n)])
will pr oduce a set containing the string versions of all integers in n:
sage: n = 2^20
sage: set([x for x in str(n)])
set([’1’, ’0’, ’5’, ’4’, ’7’, ’6’, ...