Functions | |
def | display_values |
def | display_spokes |
def | isprime |
def | test_wheel |
def | display_wheel |
def | Test_PrimeGenerator2 |
def | Test_PrimeGenerator6 |
def | Test_PrimeGenerator210 |
def | main |
def Test_Wheel::display_spokes | ( | spoke_list, | ||
wheel_list | ||||
) |
Definition at line 22 of file Test_Wheel.py.
00022 : 00023 result = "" 00024 order = len( spoke_list ) 00025 result += "o: %d\n" % order 00026 result += "s: %s\n" % spoke_list 00027 result += "w: %s\n" % wheel_list 00028 00029 ( val, str ) = display_values( 1, spoke_list ) 00030 result += str 00031 while val < 100: 00032 ( val, str ) = display_values( val, wheel_list ) 00033 result += str 00034 return result 00035 def isprime( val ):
def Test_Wheel::display_values | ( | val, | ||
list | ||||
) |
Definition at line 8 of file Test_Wheel.py.
00008 : 00009 str = "" 00010 for item in list: 00011 val += item 00012 if val >= 100: 00013 break 00014 00015 if isprime( val ): 00016 str += "%3d " % val 00017 else: 00018 str += "%3d*" % val 00019 00020 return ( val, str ) 00021 def display_spokes( spoke_list, wheel_list ):
def Test_Wheel::display_wheel | ( | spoke_list, | ||
wheel_list | ||||
) |
Definition at line 66 of file Test_Wheel.py.
00066 : 00067 max = 500 00068 p = 1 00069 for s in spoke_list[ : -1 ]: 00070 p += s 00071 00072 old_dis = display_spokes( spoke_list, wheel_list ) 00073 old_tst = test_wheel( max, spoke_list, wheel_list ) 00074 00075 wheel = Wheel.Wheel( len( spoke_list ) - 1 ) 00076 print "PrimeGenerator o: %d %d, p: %s, c: %d" % ( len( spoke_list ) - 1, wheel.order( ), wheel.primes( ), wheel.cycle( ) ) 00077 spoke_list = wheel.spokes( ) 00078 wheel_list = wheel.wheel( ) 00079 wheel_list = wheel_list[ len( spoke_list ): ] 00080 new_dis = display_spokes( spoke_list, wheel_list ) 00081 new_tst = test_wheel( max, spoke_list, wheel_list ) 00082 00083 if old_dis == new_dis: 00084 print "dis - OK" 00085 else: 00086 print "dis - diff" 00087 00088 if old_tst == new_tst: 00089 print "tst - OK" 00090 else: 00091 print "tst - diff" 00092 00093 print "pri: ", 00094 vals = [ ] 00095 p = 1 00096 for i in spoke_list[ : -1 ]: 00097 p += i 00098 vals.append( p ) 00099 print p, 00100 spoke_primes = vals 00101 print 00102 print 00103 00104 if old_dis == new_dis and old_tst == new_tst: 00105 print "s: %s" % spoke_list 00106 print "w: %s" % wheel_list 00107 for l in ( 1, 2, 3 ): 00108 for i in wheel_list: 00109 p += i 00110 vals.append( p ) 00111 print vals 00112 else: 00113 print "old_dis" 00114 print old_dis 00115 print "new_dis" 00116 print new_dis 00117 00118 print "old_tst" 00119 print old_tst 00120 print "new_tst" 00121 print new_tst 00122 00123 print 00124 def Test_PrimeGenerator2( ):
def Test_Wheel::isprime | ( | val | ) |
Definition at line 36 of file Test_Wheel.py.
00036 : 00037 p = 2 00038 while p * p < val: 00039 if val % p == 0: 00040 return False 00041 p += 1 00042 return True 00043 def test_wheel( max, spokes, wheel ):
def Test_Wheel::main | ( | ) |
Definition at line 161 of file Test_Wheel.py.
00161 : 00162 00163 for arg in sys.argv[1:]: 00164 00165 if arg[ 0 ].isdigit( ): 00166 val = int( arg ) 00167 00168 # [ 2 ] 00169 if val == 1: 00170 Test_PrimeGenerator2( ) 00171 00172 # [ 2, 3 ] -> 6 00173 if val == 2 or val == 6: 00174 Test_PrimeGenerator6( ) 00175 00176 # [ 2, 3, 5 ] -> 30 00177 if val == 3 or val == 30: 00178 Test_PrimeGenerator30( ) 00179 00180 # [ 2, 3, 5, 7 ] -> 210 00181 if val == 4 or val == 210: 00182 Test_PrimeGenerator210( ) 00183 00184 if arg[ 0 ] == "p": 00185 tokens = re.split( "=", arg ) 00186 wheel = Wheel.Wheel( int( tokens[1] ) ) 00187 primes = wheel.spokes( ) 00188 for prime in primes: 00189 print prime 00190 00191 if arg[ 0 ] == "w": 00192 tokens = re.split( "=", arg ) 00193 count = int( tokens[ 1 ] ) 00194 wheel = Wheel.Wheel( count ) 00195 00196 spokes = wheel.spokes( ) 00197 wheel = wheel.wheel( ) 00198 00199 display_spokes( count, spokes, wheel ) 00200 00201 wheel = Wheel.Wheel( count ) 00202 for n in range( 2, 100 ): 00203 if wheel.isprime( n ): 00204 print n, 00205 print 00206 if __name__ == '__main__':
def Test_Wheel::Test_PrimeGenerator2 | ( | ) |
Definition at line 125 of file Test_Wheel.py.
00125 : 00126 print "PrimeGenerator 1 2 2" 00127 primes = [ 2 ] 00128 spokes = [ 1, 1 ] 00129 wheel = [ 2 ] 00130 display_wheel( spokes, wheel ) 00131 def Test_PrimeGenerator6( ):
def Test_Wheel::Test_PrimeGenerator210 | ( | ) |
Definition at line 147 of file Test_Wheel.py.
00147 : 00148 print "PrimeGenerator 4 2,3,5,7 210" 00149 primes = [ 2, 3, 5,7 ] 00150 primes = [ 2, 3, 5, 7, 11 ] 00151 spokes = [ 1, 1, 2, 2, 4 ] 00152 wheel = [ 2, 4, 2, 4, 6, 2, 6, 4, 00153 2, 4, 6, 6, 2, 6, 4, 00154 2, 6, 4, 6, 8, 4, 00155 2, 4, 2, 4, 8, 6, 4, 00156 6, 2, 4, 6, 2, 6, 6, 00157 4, 2, 4, 6, 2, 6, 4, 00158 2, 4, 2, 10, 2, 10 ] 00159 display_wheel( spokes, wheel ) 00160 def main( ):
def Test_Wheel::Test_PrimeGenerator6 | ( | ) |
Definition at line 132 of file Test_Wheel.py.
00132 : 00133 print "PrimeGenerator 2 2,3 6" 00134 primes = [ 2, 3 ] 00135 spokes = [ 1, 1, 2 ] 00136 wheel = [ 2, 4 ] 00137 display_wheel( spokes, wheel ) 00138 00139 #def Test_PrimeGenerator30( ): 00140 # print "PrimeGenerator 3 2,3,5 30" 00141 # primes = [ 2, 3, 5 ] 00142 # spokes = [ 1, 1, 2, 2 ] 00143 # wheel = [ 4, 2, 4, 6, 2, 6, 4 ] 00144 # wheel = [ 4, 2, 4, 2, 4, 6, 2, 6 ] 00145 # display_wheel( spokes, wheel ) 00146 def Test_PrimeGenerator210( ):
def Test_Wheel::test_wheel | ( | max, | ||
spokes, | ||||
wheel | ||||
) |
Definition at line 44 of file Test_Wheel.py.
00044 : 00045 str = "" 00046 pri = 1 00047 val = 1 00048 for s in spokes: 00049 val += s 00050 str += " %s" % val 00051 if not isprime( val ): 00052 str += "*" 00053 nl = 50 00054 while True: 00055 for s in wheel: 00056 val += s 00057 str += " %s" % val 00058 if not isprime( val ): 00059 str += "*" 00060 if val >= nl: 00061 str += "\n" 00062 nl += 50 00063 if val >= max: 00064 return str 00065 def display_wheel( spoke_list, wheel_list ):