using-sage/questions.rst
changeset 408 8f4c369a41f1
parent 361 a28d592851b4
equal deleted inserted replaced
405:ae4bcaff1dde 408:8f4c369a41f1
    62 
    62 
    63 
    63 
    64 Programming
    64 Programming
    65 -----------
    65 -----------
    66 
    66 
    67 1. What is the out put of the following code::
    67 1. Obtain the sum of primes between 1 million and 2 million. 
    68 
    68 
    69      c1 = Combinations([1, 2, 3, 4])
    69    Answer::
    70      c2 = Combinations([1, 2, 4, 3])
       
    71 
    70 
    72      l1 = c1.list()
    71      prime_sum = 0
    73      l2 = c2.list()
    72      for i in range(1000001, 2000000, 2):
       
    73          if is_prime(i):
       
    74          prime_sum += i
       
    75         
       
    76      prime_sum
    74 
    77 
    75      for i in l2:
    78    OR
    76          l1.remove(i)
    79    ::
    77 
    80 
    78      print l2
    81      sum(prime_range(1000000, 2000000))
    79 
    82 
    80    Answer: []
    83 2. ``graphs.WorldMap()`` gives the world map in the form of a
       
    84    graph. ::
    81 
    85 
    82 .. #[[Anoop: add one more question to this part, probably a small
    86        G = graphs.WorldMap()
    83    problem asking them to solve it, project euler has problems on
    87        G.vertices()
    84    combinations and all]]
    88 
       
    89   
       
    90    Suppose, I wish to go from India to France by Road, find out the
       
    91    least number of Visas that I'll have to obtain. 
       
    92 
       
    93    Answer::
       
    94 
       
    95       G.distance("India", "France")
       
    96 
       
    97       
       
    98 
       
    99