lint fixes

This commit is contained in:
lukew3
2021-10-09 13:57:07 -04:00
parent 78b82a7888
commit 9d68d585b2
3 changed files with 29 additions and 21 deletions

View File

@@ -1,25 +1,33 @@
from .__init__ import *
def greatestCommonDivisorOfTwoNumbers(number1, number2):
number1 = abs(number1)
number2 = abs(number2)
while number2>0: number1, number2 = number2, number1%number2
while number2 > 0:
number1, number2 = number2, number1 % number2
return number1
def generator_function(numbersCount=2, maximalNumberLimit=10**9, format='string'):
numbersCount = max(numbersCount, 2)
numbers = [ random.randint(0, maximalNumberLimit) for number in range(numbersCount) ]
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(numbers[0], numbers[1])
def gen_func(numbersCount=2, maximalNumberLimit=10**9, format='string'):
numbersCount = max(numbersCount, 2)
numbers = [random.randint(0, maximalNumberLimit)
for number in range(numbersCount)]
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(
numbers[0], numbers[1])
for index in range(1, numbersCount):
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(numbers[index], greatestCommonDivisor)
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(
numbers[index], greatestCommonDivisor)
if format == "string":
return "GCD(" + ",".join(map(str, numbers)) + ") = " + str(greatestCommonDivisor)
elif format == "latex":
return ("\\(GCD(" + ",".join(map(str, numbers)) + f") = {greatestCommonDivisor}\\)")
else: return greatestCommonDivisor
else:
return greatestCommonDivisor
greatest_common_divisor = Generator("Greatest Common Divisor of N Numbers", 999, generator_function, ["maximalNumberLimit=1000000000"])
greatest_common_divisor = Generator("Greatest Common Divisor of N Numbers", 115, gen_func, [
"numbersCount=2", "maximalNumberLimit=10**9"])

View File

@@ -4,10 +4,10 @@ import math
def gen_func(maxN=100, format='string'):
golden_ratio = (1 + math.sqrt(5)) / 2
gratio = (1 + math.sqrt(5)) / 2
n = random.randint(1, maxN)
problem = f"What is the {n}th Fibonacci number?"
ans = int((math.pow(golden_ratio, n) - math.pow(-golden_ratio, -n)) / (math.sqrt(5)))
ans = int((math.pow(gratio, n) - math.pow(-gratio, -n)) / (math.sqrt(5)))
if format == 'string':
return problem, str(ans)

View File

@@ -14,23 +14,23 @@ def gen_func(maxDecimal=4000, format='string'):
500: "D",
1000: "M"
}
divisor = 1
while x >= divisor:
divisor *= 10
divisor /= 10
div = 1
while x >= div:
div *= 10
div /= 10
solution = ""
while x:
last_value = int(x / divisor)
last_value = int(x / div)
if last_value <= 3:
solution += (roman_dict[divisor] * last_value)
solution += (roman_dict[div] * last_value)
elif last_value == 4:
solution += (roman_dict[divisor] + roman_dict[divisor * 5])
solution += (roman_dict[div] + roman_dict[div * 5])
elif 5 <= last_value <= 8:
solution += (roman_dict[divisor * 5] + (roman_dict[divisor] * (last_value - 5)))
solution += (roman_dict[div * 5] + (roman_dict[div] * (last_value - 5)))
elif last_value == 9:
solution += (roman_dict[divisor] + roman_dict[divisor * 10])
x = math.floor(x % divisor)
divisor /= 10
solution += (roman_dict[div] + roman_dict[div * 10])
x = math.floor(x % div)
div /= 10
if format == 'string':
problem = "The number " + str(x) + " in Roman Numerals is: "