Esempio n. 1
0
    Args:
        n -- int to be named
        hyphen --bool, use hyphens for numbers like forty-eight
        use_and -- bool, use the phrasing "hundred and" rather than just "hundred"
        long_scale -- bool, use the long scale where (1,000,000 = 'one thousand million')
    
    With short scale goes up to 65 digit numbers
    With long scale goes up to 122 digit numbers
    """

    for n in naturals():
        yield int_to_name(n, hyphen, use_and, long_scale)


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("\nNames of Natural Numbers")
    simple_test(
        number_names_str(hyphen=True), 16,
        "zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen"
    )

    print("\nRoman Numerals")
    simple_test(roman_numerals_str(), 13,
                "I, II, III, IV, V, VI, VII, VIII, IX, X, XI, XII, XIII")

    print("\nRoman Numerals (numeric)")
    simple_test(roman_numerals(), 6,
                "(1,), (1, 1), (1, 1, 1), (1, 5), (5,), (5, 1)")
Esempio n. 2
0
    while True:
        yield R0[0]
        R2 = [R1[-1]]

        for i in R1:
            R2.append(i + R2[-1])

        R0, R1 = R1, R2


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("\nBinary Relations")
    simple_test(relation(), 7, "1, 2, 16, 512, 65536, 33554432, 68719476736")

    print("\nReflexive Relations")
    simple_test(reflexive_relation(), 7,
                "1, 1, 4, 64, 4096, 1048576, 1073741824")

    print("\nTotal Orders")
    simple_test(total_order(), 10,
                "1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880")

    print("\nEquivalence Relations")
    simple_test(equivalence_relation(), 10,
                "1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147")

    # print("\nPartial Orders")
    # simple_test(partial_order(),10,
Esempio n. 3
0
    diga = int_to_digits(a, B)

    sq = sqrt_digits(c, B)
    pr = real_prod_nat(sq, b, B)
    sm = real_sum(pr, diga, B)
    M = real_div_nat(sm, d, B)

    yield from dropwhile(lambda x: x == 0, M)


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("Pi, the Circle Constant")
    simple_test(pi_digits(), 18,
                "3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3")

    print("\nTau, Twice Pi")
    simple_test(real_prod_nat(
        pi_digits(),
        2,
    ), 18, "6, 2, 8, 3, 1, 8, 5, 3, 0, 7, 1, 7, 9, 5, 8, 6, 4, 7")

    print("\nPhi, The Golden Ratio")
    simple_test(phi_digits(), 18,
                "1, 6, 1, 8, 0, 3, 3, 9, 8, 8, 7, 4, 9, 8, 9, 4, 8, 4")

    print("\nSquare Root of 2")
    simple_test(sqrt_digits(2), 18,
                "1, 4, 1, 4, 2, 1, 3, 5, 6, 2, 3, 7, 3, 0, 9, 5, 0, 4")
Esempio n. 4
0
    OEIS A296063
    """
    
    for i in arithmetic(1,2):
        yield i
        yield -i





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("Counting Numbers")
    simple_test(counting(),16,
                "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16")
    
    print("\nNatural Numbers")
    simple_test(naturals(),16,
                "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15")
    
    print("\nIntegers")
    simple_test(integers(),16,
                "0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8")
    
    print("\nEven Naturals")
    simple_test(evens(),15,
                "0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28")
    
    print("\nEven Integers")
    simple_test(gen_evens(),14,
Esempio n. 5
0
    OEIS 
    """
    


def free_tree():
    """
    Number of unique free trees with n unlabeled nodes
    OEIS A000055
    """
    





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("\nNumber of Nodes in a Full Ternary Tree")
    simple_test(max_tree_nodes(3),10,
                "1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524")
    
    print("\nNumber of unique oriented trees with n unlabeled nodes")
    simple_test(rooted_tree(),12,
                "0, 1, 1, 2, 4, 9, 20, 48, 115, 286, 719, 1842")
    
    print("\nNumber Binary Trees of Height n")
    simple_test(binary_tree(),7,
                "1, 1, 3, 21, 651, 457653, 210065930571")
    
Esempio n. 6
0
    for n, f in enumerate(prime_signatures(), 1):
        total = 0
        for m in f:
            while m != 0:
                m, r = divmod(m, 2)
                total ^= r
        if total == 0:
            yield n


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("Primes")
    simple_test(primes(), 15,
                "2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47")

    print("\nPrimorials")
    simple_test(primorial(), 9,
                "1, 2, 6, 30, 210, 2310, 30030, 510510, 9699690")

    print("\nPrime Powers")
    simple_test(prime_powers(), 16,
                "1, 2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19, 23, 25, 27")

    print("\nPythagorean Primes")
    simple_test(pythagorean_primes(), 13,
                "5, 13, 17, 29, 37, 41, 53, 61, 73, 89, 97, 101, 109")

    print("\nPrime Counting Function")
    simple_test(prime_counting(), 18,
Esempio n. 7
0
    
    yield 1
    
    for a in arithmetic(2,2):
        if srinivasan_ineq(a):
            yield a





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("Aliquot Sums")
    simple_test(aliquot(),17,
                "0, 1, 1, 3, 1, 6, 1, 7, 4, 8, 1, 16, 1, 10, 9, 15, 1")

    print("\nAliquot Sequence of 276")
    simple_test(aliquot_recurrence(276),9,
                "276, 396, 696, 1104, 1872, 3770, 3790, 3050, 2716")
    
    print("\nAbundant Numbers")
    simple_test(abundant(),14,
                "12, 18, 20, 24, 30, 36, 40, 42, 48, 54, 56, 60, 66, 70")
    
    print("\nPrimitive Abundant Numbers (Type 1, all deficient factors)")
    simple_test(primitive_abundant_1(),12,
                "20, 70, 88, 104, 272, 304, 368, 464, 550, 572, 650, 748")
    
    print("\nPrimitive Abundant Numbers (Type 2, no abundant factors)")
    simple_test(primitive_abundant_2(),13,
Esempio n. 8
0
    
    OEIS A007434, A059376, A059377, A059378, A069091-A069095
    """
    
    for n in naturals(1):
        yield jordan_totient(n,k)





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("Totient Sequence")
    simple_test(totients(),16,
                "1, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, 4, 12, 6, 8, 8, 16")
    
    print("\nJordan 2-Totients")
    simple_test(jordan_totients(2),13,
                "1, 3, 8, 12, 24, 24, 48, 48, 72, 72, 120, 96, 168")
    
    print("\nCharmichael Function")
    simple_test(charmichael(),17,
                "1, 1, 2, 2, 4, 2, 6, 2, 6, 4, 10, 2, 12, 6, 4, 4, 16")
    
    print("\nCototient Numbers")
    simple_test(cototients(),18,
                "0, 1, 1, 2, 1, 4, 1, 4, 3, 6, 1, 8, 1, 8, 7, 8, 1, 12")
    
    print("\nRange of the Totient Function")
    simple_test(totient_range(),15,
Esempio n. 9
0
    while True:
        x ^= (x << 13)%(2**32)
        x ^= (x >> 17)%(2**32)
        x ^= (x << 5)%(2**32)
        
        yield x





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("Linear Congruential Generator")
    simple_test(LCG(9,5,17,97),14,
                "9, 62, 36, 3, 32, 80, 29, 65, 51, 78, 19, 15, 92, 89")
    
    print("\nRANDU, lower 16 bits (note only odd values)")
    simple_test(lower_bits(RANDU(2127401289),16),8,
                "37193, 46043, 7057, 21171, 63513, 59467, 47329, 10915")
    
    print("\nRANDU, upper 16 bits")
    simple_test(upper_bits(RANDU(2127401289),16),8,
                "32461, 3505, 23792, 12897, 27094, 13725, 2340, 21583")
    
    print("\nMINSTD, lower 16 bits")
    simple_test(lower_bits(MINSTD(2127401289),16),8,
                "37193, 32402, 23247, 27161, 9001, 55737, 34452, 60993")
    
    print("\nCompound LCG, lower 16 bits")
    simple_test(lower_bits(
Esempio n. 10
0
    yield 1

    while True:
        yield P

        a, b = b, a + b

        P *= a


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("Factorials")
    simple_test(factorials(), 11,
                "1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800")

    print("\nAlternating Factorials (A005165)")
    simple_test(alternating_factorials_1(), 11,
                "0, 1, 1, 5, 19, 101, 619, 4421, 35899, 326981, 3301819")

    print("\nAlternating Factorials (A058006)")
    simple_test(alternating_factorials_2(), 10,
                "1, 0, 2, -4, 20, -100, 620, -4420, 35900, -326980")

    print("\nKempner Function")
    simple_test(kempner(), 17,
                "1, 2, 3, 4, 5, 3, 7, 4, 6, 5, 11, 4, 13, 7, 5, 6, 17")

    print("\nDouble Factorials")
    simple_test(double_factorials(), 12,
Esempio n. 11
0
    return RULE, RULE_str, RULE_black, RULE_white


rule_30, rule_30_str, rule_30_black, rule_30_white = make_wolfram_code(
    R30, R30_str)
rule_90, rule_90_str, rule_90_black, rule_90_white = make_wolfram_code(
    R90, R90_str)
rule_110, rule_110_str, rule_110_black, rule_110_white = make_wolfram_code(
    R110, R110_str)

if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("\nRule 30")
    simple_test(rule_30_str(), 6,
                "#, ###, ##  #, ## ####, ##  #   #, ## #### ###")

    print("\nRule 30 Black")
    simple_test(rule_30_black(), 16,
                "1, 3, 3, 6, 4, 9, 5, 12, 7, 12, 11, 14, 12, 19, 13, 22")

    print("\nRule 30 White")
    simple_test(rule_30_white(), 17,
                "0, 0, 2, 1, 5, 2, 8, 3, 10, 7, 10, 9, 13, 8, 16, 9, 18")

    print("\nRule 90")
    simple_test(rule_90_str(), 6,
                "#, # #, #   #, # # # #, #       #, # #     # #")

    print("\nRule 90 Black")
    simple_test(rule_90_black(), 18,
Esempio n. 12
0
    """
    Triples of positive integers a,b,c such that 1/a + 1/b = 1/c\n
    OEIS
    """

    for m in naturals(1):
        for n in range(1, m):
            if gcd(m, n) == 1:
                yield (m * (m + n), n * (m + n), m * n)


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("Nonhypotenuse Numbers")
    simple_test(nonhypotenuse(), 16,
                "1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 14, 16, 17, 18, 19, 21")

    print("\nHypotenuse Numbers")
    simple_test(hypotenuse(), 14,
                "5, 10, 13, 15, 17, 20, 25, 26, 29, 30, 34, 35, 37, 39")

    print("\nPythagorean Triples")
    simple_test(pythagorean_triples(), 4,
                "(3, 4, 5), (6, 8, 10), (5, 12, 13), (9, 12, 15)")

    # print("\nPythagorean Perimeters")
    # simple_test(pythagorean_perimeters(),13,
    #             "12, 30, 40, 56, 70, 84, 90, 126, 132, 144, 154, 176")

    print("\nPrimitive Hypotenuse Numbers")
    simple_test(primitive_hypotenuse(), 14,
    Convergents of Euler's Number (also the semiconvergents of e)
    
    Args:
        mode -- str, 'f' yields fractions, 'n' yields the numerators, 'd' yields the denominators
    
    OEIS
    """

    yield from convergents(e_cfrac(), mode=mode)


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("\nContinued Fraction for √2")
    simple_test(sqrt_cfrac(2), 18,
                "1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2")

    print("\nConvergents of √2")
    simple_test(sqrt_convergents(2), 8,
                "1, 3/2, 7/5, 17/12, 41/29, 99/70, 239/169, 577/408")

    print("\nSemiconvergents of √2")
    simple_test(sqrt_semiconvergents(2), 9,
                "1, 2, 3/2, 4/3, 7/5, 10/7, 17/12, 24/17, 41/29")

    print("\nContinued Fraction for Euler's Number, e")
    simple_test(e_cfrac(), 17,
                "2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1")

    print("\nConvergents of e")
    simple_test(e_convergents(), 8,
Esempio n. 14
0
    
    F = fibonacci()
    
    while True:
        next(F)
        yield next(F)





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("Fibonacci Sequence")
    simple_test(fibonacci(),15,
                "0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377")
    
    print("\nLucas Numbers")
    simple_test(lucas(),14,
                "2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, 521")
    
    print("\nLucas Sequence U(-1,3)")
    simple_test(lucas_U(-1,3),13,
                "0, 1, -1, -2, 5, 1, -16, 13, 35, -74, -31, 253, -160")
    
    print("\nLucas Sequence V(3,-5)")
    simple_test(lucas_V(3,-5),10,
                "2, 3, 19, 72, 311, 1293, 5434, 22767, 95471, 400248")
    
    print("\nSignature Sequence {3,1,1}")
    simple_test(signature_function([3,1,1]),10,
    
    D = {"F": "F+F-F-F+F",
         "+": "+",
         "-": "-"}
    
    S = "F"
    
    while True:
        yield S
        
        t = ""
        
        for s in S:
            t += D[s]
        
        S = t





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("Fractal Tree")
    simple_test(fractal_tree_str(),4,
                "0, 1[0]0, 11[1[0]0]1[0]0, 1111[11[1[0]0]1[0]0]11[1[0]0]1[0]0")
    
    print("\nKoch Curve")
    simple_test(koch_curve_str(),3,
                "F, F+F-F-F+F, F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F")
Esempio n. 16
0
    while True:
        yield S

        t = ()

        for s in S:
            t += D[s]

        S = t


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("Thue-Morse Sequence")
    simple_test(thue_morse(), 18,
                "0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0")

    print("\nThue-Morse Words")
    simple_test(thue_morse_words(), 4,
                "(0,), (0, 1), (0, 1, 1, 0), (0, 1, 1, 0, 1, 0, 0, 1)")

    print("\nInfinite Fibonacci Word")
    simple_test(fibonacci_word(), 18,
                "0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1")

    print("\nFinite Fibonacci Words")
    simple_test(fibonacci_words(), 4,
                "(0,), (0, 1), (0, 1, 0), (0, 1, 0, 0, 1)")

    print("\nGray Codes")
    simple_test(gray_codes(), 6,
Esempio n. 17
0
    require_integers(["k", "m"], [k, m])

    n = 0

    while True:
        yield n

        n = (n + k) % m


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("Triangle of Modular Inverses")
    simple_test(modular_inverses(), 4, "(1,), (1, 2), (1, 0, 3), (1, 3, 2, 4)")

    print("\nIrregular Array of Legendre Symbols")
    simple_test(legendre_symbols(), 3, "(0, 1), (0, 1, -1), (0, 1, -1, -1, 1)")

    print("\nIrregular Array of Jacobi Symbols")
    simple_test(jacobi_symbols(), 3, "(1,), (0, 1, -1), (0, 1, -1, -1, 1)")

    print("\nTriangle of Kronecker Symbols")
    simple_test(kronecker_symbols(), 17,
                "1, 0, -1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 1")

    print("\nMobius Function")
    simple_test(mobius_function(), 16,
                "1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0")
Esempio n. 18
0
    for n in naturals(1):
        l = [i for i in _coin_partions_recur(n,S)]
        yield len(l)


#def fibonacci_partitions(n,S):





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("Partition Numbers")
    simple_test(partition_count(),15,
                "1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101, 135")
    
    print("\nPartitions of 4")
    simple_test(partitions(4),8,
                "(4,), (3, 1), (2, 2), (2, 1, 1), (1, 1, 1, 1)")
    
    print("\nSequence of All Partitions")
    simple_test(all_partitions(),8,
                "(), (1,), (2,), (1, 1), (3,), (2, 1), (1, 1, 1), (4,)")
    
    print("\nPartition Order")
    simple_test(partition_ordering(),16,
                "1, 2, 3, 4, 5, 6, 8, 7, 10, 9, 12, 16, 11, 14, 15, 20")
    
    print("\nEqual Partitions of 6")
    simple_test(equal_partitions(6),16,
Esempio n. 19
0
    """
    
    S = stern_diatomic()
    
    while True:
        yield Fraction(next(S),next(S))




if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    from Sequences.Simple import sign_sequence
    
    print("\nHarmonic Sequence")
    simple_test(_pretty_fracs(harmonic()),8,
                "1/1, 3/2, 11/6, 25/12, 137/60, 49/20, 363/140, 761/280")
    
    print("\nHarmonic Denominators")
    simple_test(denominators(harmonic()),11,
                "1, 2, 6, 12, 60, 20, 140, 280, 2520, 2520, 27720")
    
    print("\nGeneralized Harmonic Sequence of Order 2")
    simple_test(_pretty_fracs(gen_harmonic(2)),6,
                "1/1, 5/4, 49/36, 205/144, 5269/3600, 5369/3600")
    
    print("\nGeneralized Harmonic Numerators of Order 2")
    simple_test(numerators(gen_harmonic(2)),9,
                "1, 5, 49, 205, 5269, 5369, 266681, 1077749, 9778141")
    
    print("\nIrregular Triangle of Farey Sequences")
    simple_test(_pretty_fracs(farey()),11,
Esempio n. 20
0
        
        while val >= n and val != 1:
            ctr += 1
            val = _collatz_step(val)
        
        yield ctr





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("Collatz Map")
    simple_test(collatz_map(),16,
                "0, 4, 1, 10, 2, 16, 3, 22, 4, 28, 5, 34, 6, 40, 7, 46")
    
    print("\nReduced Collatz Map")
    simple_test(reduced_collatz_map(),16,
                "0, 2, 1, 5, 2, 8, 3, 11, 4, 14, 5, 17, 6, 20, 7, 23")
    
    print("\nCollatz Sequence of 11")
    simple_test(collatz(11),18,
                "11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1")
    
    print("\nReduced Collatz Sequence of 11")
    simple_test(reduced_collatz_sequence(11),18,
                "11, 17, 26, 13, 20, 10, 5, 8, 4, 2, 1")
    
    print("\nLength of the Collatz Sequences")
    simple_test(collatz_length(),16,
Esempio n. 21
0
    P = [1]

    for a in A:
        yield poly_mult([a], P)

        P = poly_mult([1, -c], P)


def taylor_sums(A, c=0):
    """
    Coefficients of each partial sum of the Talyor Series defined by the sequence A and constant c\n
    """

    require_iterable(["A"], [A])
    require_integers(["c"], [c])

    S = [0]

    for P in taylor_terms(A, c):
        S = poly_sum(P, S)

        yield S


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    simple_test(taylor_terms(naturals(1), 1), 5, "")

    simple_test(taylor_sums(naturals(1), 1), 5, "")
Esempio n. 22
0
    """
    Star Numbers: Equivalent to the centered 12-gonal numbers\n
    OEIS A003154
    """

    yield 0

    for n in naturals(1):
        yield 6 * n * (n - 1) + 1


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("Triangular Numbers")
    simple_test(triangular(), 14,
                "0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91")

    print("\nSquare Numbers")
    simple_test(square(), 13,
                "0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144")

    print("\nPentagonal Numbers")
    simple_test(pentagonal(), 13,
                "0, 1, 5, 12, 22, 35, 51, 70, 92, 117, 145, 176, 210")

    print("\nGeneralized Pentagonal Numbers")
    simple_test(gen_pentagonal(), 14,
                "0, 1, 2, 5, 7, 12, 15, 22, 26, 35, 40, 51, 57, 70")

    print("\nHexagonal Numbers")
    simple_test(polygonal(6), 13,
Esempio n. 23
0
        for k in range(n+1):
            a += comb(n,k)*A[k]*A[n-k]
        
        yield a
        A.append(a//2)





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("Combinatoric Counting Sequences")
    print("\nDerangement Numbers")
    simple_test(derangement(),11,
                "1, 0, 1, 2, 9, 44, 265, 1854, 14833, 133496, 1334961")
    
    print("\nEven Permutation Numbers")
    simple_test(even_permutation(),11,
                "1, 1, 1, 3, 12, 60, 360, 2520, 20160, 181440, 1814400")
    
    print("\nOdd Permutation Numbers")
    simple_test(odd_permutation(),11,
                "0, 0, 1, 3, 12, 60, 360, 2520, 20160, 181440, 1814400")
    
    print("\nRecontres Numbers")
    simple_test(recontres(),17,
                "1, 0, 1, 1, 0, 1, 2, 3, 0, 1, 9, 8, 6, 0, 1, 44, 45")
    
    print("\nAlternating Permutation Numbers")
    simple_test(alternating_permutation(),11,
Esempio n. 24
0
        # Check with a Lucas V-Sequence
        if lucas_U_test(n, d, P, Q):
            yield n
            continue

        # Check with a Lucas V-Sequence
        if lucas_V_test(n, d, s, P, Q):
            yield n


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("\nFermat Pseudoprimes to Base 3")
    simple_test(fermat_pseudoprimes(3), 10,
                "91, 121, 286, 671, 703, 949, 1105, 1541, 1729, 1891")

    print("\nCipolla Pseudoprimes to Base 3")
    simple_test(cipolla_pseudoprimes(3), 4,
                "7381, 597871, 3922632451, 317733228541")

    # print("\nCharmichael Numbers")
    # simple_test(carmichael_numbers(),9,
    #             "561, 1105, 1729, 2465, 2821, 6601, 8911, 10585, 15841")

    print("\nWeak Pseudoprimes to Base 3")
    simple_test(weak_pseudoprimes(3), 12,
                "1, 6, 66, 91, 121, 286, 561, 671, 703, 726, 949, 1105")

    print("\nStrong Pseudoprimes to Base 3")
    simple_test(strong_pseudoprimes(3), 9,
Esempio n. 25
0
    The number of sum-free subsets of the set {1...n} for all naturals n
    OEIS A007865
    """
    
    for n in naturals():
        yield len([i for i in sum_free_subsets(n)])





if __name__ == '__main__':
    from Sequences.Manipulations import simple_test
    
    print("\nCatalan Numbers")
    simple_test(catalan(),11,
                "1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796")
    
    print("\nCo-Catalan Numbers")
    simple_test(co_catalan(),11,
                "0, 1, 4, 15, 56, 210, 792, 3003, 11440, 43758, 167960")
    
    print("\nPascal's Triangle by Rows")
    simple_test(pascal_triangle(),5,
                "(1,), (1, 1), (1, 2, 1), (1, 3, 3, 1), (1, 4, 6, 4, 1)")
    
    print("\nCentral Binomial Coefficients")
    simple_test(central_binomial(),11,
                "1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620, 184756")
    
    print("\nGould's Sequence")
    simple_test(gould(),18,
Esempio n. 26
0
    for n in naturals():
        D = int_to_digits(n, B)
        d = len(D)
        if d < l:
            continue

        elif _subseq(S, D):
            yield D


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("Evil Numbers (Even Number of 1s in Binary Expansion)")
    simple_test(evil(), 15,
                "0, 3, 5, 6, 9, 10, 12, 15, 17, 18, 20, 23, 24, 27, 29")

    print("\nOdious Numbers (Odd Number of 1s in Binary Expansion)")
    simple_test(odious(), 15,
                "1, 2, 4, 7, 8, 11, 13, 14, 16, 19, 21, 22, 25, 26, 28")

    print("\nBinary Weights")
    simple_test(binary_weight(), 18,
                "0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2")

    print("\nComplementary Binary Weights")
    simple_test(co_binary_weight(), 18,
                "1, 0, 1, 0, 2, 1, 1, 0, 3, 2, 2, 1, 2, 1, 1, 0, 4, 3")

    print("\nBinary Lengths")
    simple_test(binary_length(), 18,
Esempio n. 27
0
    yield 1
    yield 2

    L = [2]

    for digit in cycle([1, 2]):
        run = L.pop(0)
        L += [digit] * run
        yield run


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("Recaman's Sequence")
    simple_test(recaman(), 15,
                "0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9")

    print(
        "\nIntegers that represent the Cantor pairing function a of fully reduced proper fraction"
    )
    simple_test(cantor_pairs(), 14,
                "8, 13, 18, 19, 26, 32, 33, 34, 41, 43, 50, 52, 53, 62")

    print("\nGCD Numbers")
    simple_test(gcd_numbers(), 5,
                "(1,), (1, 1), (1, 2, 1), (1, 1, 1, 1), (1, 2, 3, 2, 1)")

    print("\nEuclid's GCD Steps")
    simple_test(gcd_steps(), 5,
                "(1,), (2, 2), (3, 1, 3), (4, 3, 3, 4), (5, 2, 1, 2, 5)")
Esempio n. 28
0
    for n in odds():
        val = n
        ctr = 0

        while val >= n and val != 1:
            ctr += 1
            val = _juggler_step(val)

        yield ctr


if __name__ == '__main__':
    from Sequences.Manipulations import simple_test

    print("\nJuggler Sequence Starting with 2051")
    simple_test(juggler(2051), 5,
                "2051, 92885, 28308599, 150618238728, 388095")

    print("\nJuggler Map")
    simple_test(juggler_map(), 16,
                "0, 1, 1, 5, 2, 11, 2, 18, 2, 27, 3, 36, 3, 46, 3, 58")

    print("\nJuggler Sequence Lengths")
    simple_test(juggler_length(), 18,
                "0, 1, 6, 2, 5, 2, 4, 2, 7, 7, 4, 7, 4, 7, 6, 3, 4, 3")

    print("\nGreatest Juggler Lengths")
    simple_test(juggler_longest(), 12,
                "1, 2, 3, 9, 19, 25, 37, 77, 163, 193, 1119, 1155")

    print("\nJuggler High Points")
    simple_test(juggler_highpoint(), 15,