mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
lint fixes
This commit is contained in:
@@ -1,25 +1,33 @@
|
|||||||
from .__init__ import *
|
from .__init__ import *
|
||||||
|
|
||||||
|
|
||||||
def greatestCommonDivisorOfTwoNumbers(number1, number2):
|
def greatestCommonDivisorOfTwoNumbers(number1, number2):
|
||||||
number1 = abs(number1)
|
number1 = abs(number1)
|
||||||
number2 = abs(number2)
|
number2 = abs(number2)
|
||||||
while number2>0: number1, number2 = number2, number1%number2
|
while number2 > 0:
|
||||||
|
number1, number2 = number2, number1 % number2
|
||||||
return number1
|
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):
|
for index in range(1, numbersCount):
|
||||||
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(numbers[index], greatestCommonDivisor)
|
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(
|
||||||
|
numbers[index], greatestCommonDivisor)
|
||||||
|
|
||||||
if format == "string":
|
if format == "string":
|
||||||
return "GCD(" + ",".join(map(str, numbers)) + ") = " + str(greatestCommonDivisor)
|
return "GCD(" + ",".join(map(str, numbers)) + ") = " + str(greatestCommonDivisor)
|
||||||
elif format == "latex":
|
elif format == "latex":
|
||||||
return ("\\(GCD(" + ",".join(map(str, numbers)) + f") = {greatestCommonDivisor}\\)")
|
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"])
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import math
|
|||||||
|
|
||||||
|
|
||||||
def gen_func(maxN=100, format='string'):
|
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)
|
n = random.randint(1, maxN)
|
||||||
problem = f"What is the {n}th Fibonacci number?"
|
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':
|
if format == 'string':
|
||||||
return problem, str(ans)
|
return problem, str(ans)
|
||||||
|
|||||||
@@ -14,23 +14,23 @@ def gen_func(maxDecimal=4000, format='string'):
|
|||||||
500: "D",
|
500: "D",
|
||||||
1000: "M"
|
1000: "M"
|
||||||
}
|
}
|
||||||
divisor = 1
|
div = 1
|
||||||
while x >= divisor:
|
while x >= div:
|
||||||
divisor *= 10
|
div *= 10
|
||||||
divisor /= 10
|
div /= 10
|
||||||
solution = ""
|
solution = ""
|
||||||
while x:
|
while x:
|
||||||
last_value = int(x / divisor)
|
last_value = int(x / div)
|
||||||
if last_value <= 3:
|
if last_value <= 3:
|
||||||
solution += (roman_dict[divisor] * last_value)
|
solution += (roman_dict[div] * last_value)
|
||||||
elif last_value == 4:
|
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:
|
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:
|
elif last_value == 9:
|
||||||
solution += (roman_dict[divisor] + roman_dict[divisor * 10])
|
solution += (roman_dict[div] + roman_dict[div * 10])
|
||||||
x = math.floor(x % divisor)
|
x = math.floor(x % div)
|
||||||
divisor /= 10
|
div /= 10
|
||||||
|
|
||||||
if format == 'string':
|
if format == 'string':
|
||||||
problem = "The number " + str(x) + " in Roman Numerals is: "
|
problem = "The number " + str(x) + " in Roman Numerals is: "
|
||||||
|
|||||||
Reference in New Issue
Block a user