def search_sevenths(first, second, third, fourth): """ Prints out a list of seventh chords and their respective keys that match the specified chord. Usually there will only be one result; the general exception is when the notes form a diminished seventh, since any particular set of notes form a valid diminished seventh in four different keys. """ first, second, third, fourth = ( key_to_index(first), key_to_index(second), key_to_index(third), key_to_index(fourth), ) for key, seventh_map in ALL_SEVENTHS.items(): for seventh_name, note_list in seventh_map.items(): if [first, second, third, fourth] in rotations(note_list): print "Match: " + KEY_NAMES[key][0].ljust(3) + seventh_name
def is_circular_prime(n): if any(not is_prime(rot) for rot in rotations(n)): return False return True
def is_circular(num): return all(is_prime(rotated) for rotated in rotations(num))
#!/usr/bin/python import utils primes = utils.FastPrimeSieve(1000000) if __name__ == "__main__": cprimes = [] p = {} print "Generating rotations" for prime in primes: p[prime] = utils.rotations(prime) print "Computing circular primes" for n, rots in p.items(): circular = True for item in rots: try: p[item] except KeyError: circular = False break if circular: cprimes.append(prime) print len(cprimes)