Esempio n. 1
0
# D(n) -- Count of Euclid modulus operations for the GCD
# Will calculate  50 iterations
print("\n## Running D(n) ##")
print("iteratively building fibonacci sequnece array for D(n)")
iterations = 51  # iterations will become 50 due to range() function
fib_seq_literal = [0, 1]
for n in range(2, 51):
    fib_seq_literal.append(fib_seq_literal[n - 1] + fib_seq_literal[n - 2])

gcd_mods_arr = []
for n in range(0, 50):
    gcd_mods_arr.append(0)
    a = fib_seq_literal[n + 1]
    b = fib_seq_literal[n]
    gcd.gcd(a, b, gcd_mods_arr, n)
print("D(n) complete")

# M(n) -- Count of multiplications for three different
# implementations of exponentiation
print("\n## Running M(n) ##")
dbo_arr, dbf_arr, dac_arr = [], [], []
for n in range(0, 51):
    dbo_arr.append(0)
    dbf_arr.append(0)
    dac_arr.append(0)
    exp.dec_by_one(2, n, dbo_arr, n)
    exp.dec_by_fctr(2, n, dbf_arr, n)
    exp.div_and_conq(2, n, dac_arr, n)
print("M(n) complete")
Esempio n. 2
0
while response == 'y' or response == 'Y':
    fib_arr, gcd_arr = [0], [0]
    placeholder = [0]

    task_1_prompt_file = open('task_1_prompt.txt')
    task_1_prompt = task_1_prompt_file.read()

    print(task_1_prompt)

    k = int(input("Enter a value for 'k' (recommended k < 36):"))

    print("Fib(", k, ") is:", fib.fib(k, fib_arr, 0))
    print("Additions:", fib_arr[0])
    m = fib.fib(k + 1, placeholder, 0)
    n = fib.fib(k, placeholder, 0)
    print("GCD(", m, ",", n, ") is:", gcd.gcd(m, n, gcd_arr, 0))
    print("Modulos:", gcd_arr[0])

    task_1_prompt_file.close()

    response = input("Would you like to repeat this task? y/n: ")
    while response not in responses:
        print(
            "Please enter 'y' to repeat or 'n' to continue to the next task.")
        response = input("Would you like to repeat this task? y/n: ")
    print("\n")

response = 'y'
while response == 'y' or response == 'Y':
    dbo_arr, dbf_arr, dac_arr = [0], [0], [0]
    task_2_prompt_file = open('task_2_prompt.txt')
Esempio n. 3
0
 def testGcdCase1(self):
     self.assertEquals(gcd(8, 3), 1)
Esempio n. 4
0
 def testGcd(self):
     self.assertEquals(gcd(8, 4), 4)
Esempio n. 5
0
 def test_true_case2(self):
     self.assertEqual(gcd(360, 465), 15)
Esempio n. 6
0
 def testGcdCase0(self):
     self.assertEquals(gcd(8, 0), 8)
Esempio n. 7
0
 def test_true_case1(self):
     self.assertEqual(gcd(36, 48), 12)
Esempio n. 8
0
 def testGcdCase0(self):
     self.assertEquals(gcd(8, 0), 8)
Esempio n. 9
0
 def testGcd(self):
     self.assertEquals(gcd(8, 4), 4)
Esempio n. 10
0
 def testGcdCase1(self):
     self.assertEquals(gcd(8, 3), 1)
Esempio n. 11
0
def lcm(a, b):
    return abs(a * b) / gcd(a=a, b=b)