Пример #1
0
def primes(max=None):
    p = 2
    while max == None or p <= max:
        if is_prime(p):
            yield p
        p += 1
Пример #2
0

if __name__ == '__main__':
    from goody import irange
    # Test peaks; add your own test cases
    print('Testing peaks')
    print(peaks([0, 1, -1, 3, 8, 4, 3, 5, 4, 3, 8]))
    print(peaks([5, 2, 4, 9, 6, 1, 3, 8, 0, 7]))
    print(peaks([1, 2, 3, 4, 5]))
    print(peaks([0, 1]))

    #prints a 1 for every prime preceded/followed by a non prime
    #below 5, 7, 11, 13, 17, 19 have that property the result should be a list of 6 1s
    #[1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20]
    #[0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0]
    print(list(int(is_prime(p)) for p in irange(1, 20)))
    print(peaks(int(is_prime(p)) for p in irange(1, 20)))

    # Test compress; add your own test cases
    print('\nTesting compress')
    for i in compress('abcdefghijklmnopqrstuvwxyz',
                      [is_prime(i) for i in irange(1, 26)]):
        print(i, end='')
    print()

    for i in compress('abcdefghijklmnopqrstuvwxyz',
                      (is_prime(i) for i in irange(1, 26))):
        print(i, end='')
    print('\n')

    # Test stop_when; add your own test cases
Пример #3
0
            Counter.reset(self)
        else:
            Counter.inc(self)
        
    def modulus_of(self):
        return self._modulus



# Testing Script

if __name__ == '__main__':
    
    print('Testing count')
    values = [i for i in irange(1,100)] 
    print('Count of primes in list =', sum(1 for i in values if predicate.is_prime(i)))
    for i in range(5):
        shuffle(values)
        t = add_all(None,values)
        print('Count of primes in randomly built tree =',count(t,predicate.is_prime))
              
    print('\nTesting equal')           
    a = list_to_ll(['one','two','three','four'])
    b = list_to_ll(['one','two','three','four'])
    c = list_to_ll(['one','two','three'])
    d = list_to_ll(['one','two','three','four','five'])
    e = list_to_ll(['one','two','four','four'])
    
    print('These are equal:', equal(a,b))
    print('These are unequal:',equal(a,c), equal(a,d), equal(a,e))
    
    print(sort(l))

    print('\nTesting compare')
    print(compare('', 'abc'))
    print(compare('abc', ''))
    print(compare('', ''))
    print(compare('abc', 'abc'))
    print(compare('bc', 'abc'))
    print(compare('abc', 'bc'))
    print(compare('aaaxc', 'aaabc'))
    print(compare('aaabc', 'aaaxc'))

    print('\nTesting triple and peaks')
    print(triple([[]], 'a'))
    print(triple([['a']], 'b'))
    print(triple([['a', 'b']], 'c'))
    print(triple([['a', 'b', 'c']], 'd'))
    print(triple([['a', 'b', 'c'], ['b', 'c', 'd']], 'e'))
    print(triple([['a', 'b', 'c'], ['b', 'c', 'd'], ['c', 'd', 'e']], 'f'))

    print(peaks([0, 1, -1, 3, 8, 4, 3, 5, 4, 3, 8]))
    print(peaks([5, 2, 4, 9, 6, 1, 3, 8, 0, 7]))
    print(peaks([1, 2, 3, 4, 5]))
    print(peaks(int(predicate.is_prime(p)) for p in irange(1, 20)))

    driver.default_file_name = 'bsc.txt'
    #     driver.default_show_traceback = True
    #     driver.default_show_exception = True
    #     driver.default_show_exception_message = True
    driver.driver()
Пример #5
0
 import traceback
 
 driver.driver() # type quit in driver to return and execute code below
 
 # Test increases; add your own test cases
 print('Testing peaks')
 print(peaks([0,1,-1,3,8,4,3,5,4,3,8]))
 print(peaks([5,2,4,9,6,1,3,8,0,7]))
 print(peaks([1,2,3,4,5]))
 print(peaks([0,1]))
 
 #prints a 1 for every prime preceded/followed by a non prime
 #below 5, 7, 11, 13, 17, 19 have that property the result should be a list of 6 1s
 #[1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20]
 #[0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0]
 print(list(int(is_prime(p)) for p in irange(1,20)))
 print(peaks(int(is_prime(p)) for p in irange(1,20)))
 
 
 # Test Permutation/Permuation2; add your own test cases
 print('\nTesting Permutation')
 for i in Permutation([4,0,3,1,2],0):
     print(i,end='')
 print()
 
 for i in Permutation([4,0,3,1,2],3):
     print(i,end='')
 print()
 
 for i in Permutation([0],0):
     print(i,end='')
Пример #6
0
    
    print('\nTesting compare')
    print(compare('','abc'))
    print(compare('abc',''))
    print(compare('',''))
    print(compare('abc','abc'))
    print(compare('bc','abc'))
    print(compare('abc','bc'))
    print(compare('aaaxc','aaabc'))
    print(compare('aaabc','aaaxc'))
    
    print('\nTesting triple and peaks')
    print(triple([[]],'a'))
    print(triple([['a']],'b'))
    print(triple([['a','b']],'c'))
    print(triple([['a','b','c']],'d'))
    print(triple([['a','b','c'],['b','c','d']],'e'))
    print(triple([['a','b','c'],['b','c','d'],['c','d','e']],'f'))
    
    print(peaks([0,1,-1,3,8,4,3,5,4,3,8]))
    print(peaks([5,2,4,9,6,1,3,8,0,7]))
    print(peaks([1,2,3,4,5]))
    print(peaks(int(predicate.is_prime(p)) for p in irange(1,20)))
    
    driver.default_file_name = 'bsc.txt'
#     driver.default_show_traceback         = True
#     driver.default_show_exception         = True
#     driver.default_show_exception_message = True
    driver.driver()