mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 18:33:58 -05:00
Updated to fix a few small bugs
This commit is contained in:
@@ -3,11 +3,27 @@
|
|||||||
# Created: 01-27-19
|
# Created: 01-27-19
|
||||||
#Modified: 02-09-19
|
#Modified: 02-09-19
|
||||||
#This is a file that contains a few algorithms that I have used several times
|
#This is a file that contains a few algorithms that I have used several times
|
||||||
|
"""
|
||||||
|
Copyright (C) 2019 Matthew Ellison
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
#This function returns a list with all the prime numbers <= goalNumber
|
#This function returns a list with all the prime numbers <= goalNumber
|
||||||
def getPrimes(goalNumber: int):
|
def getPrimes(goalNumber: int) -> list:
|
||||||
primes = []
|
primes = []
|
||||||
foundFactor = False
|
foundFactor = False
|
||||||
|
|
||||||
@@ -44,7 +60,7 @@ def getPrimes(goalNumber: int):
|
|||||||
return primes
|
return primes
|
||||||
|
|
||||||
#This function gets a certain number of primes
|
#This function gets a certain number of primes
|
||||||
def getNumPrimes(numberOfPrimes: int):
|
def getNumPrimes(numberOfPrimes: int) -> list:
|
||||||
primes = []
|
primes = []
|
||||||
foundFactor = False
|
foundFactor = False
|
||||||
|
|
||||||
@@ -87,10 +103,9 @@ def getNumPrimes(numberOfPrimes: int):
|
|||||||
|
|
||||||
#Return the list with all the prime numbers
|
#Return the list with all the prime numbers
|
||||||
return primes
|
return primes
|
||||||
|
|
||||||
|
|
||||||
#This is a function that returns all the factors of goalNumber
|
#This is a function that returns all the factors of goalNumber
|
||||||
def getFactors(goalNumber: int):
|
def getFactors(goalNumber: int) -> list:
|
||||||
#You need to get all the primes up to this number
|
#You need to get all the primes up to this number
|
||||||
primes = getPrimes(math.ceil(math.sqrt(goalNumber))) #If there is a prime it must be <= sqrt(num)
|
primes = getPrimes(math.ceil(math.sqrt(goalNumber))) #If there is a prime it must be <= sqrt(num)
|
||||||
factors = []
|
factors = []
|
||||||
@@ -189,6 +204,10 @@ def getAllFib(goalNumber: int) -> list:
|
|||||||
|
|
||||||
#This function returns the product of all elements in the list
|
#This function returns the product of all elements in the list
|
||||||
def prod(nums: list) -> int:
|
def prod(nums: list) -> int:
|
||||||
|
#If a blank list was sent to the function return 0 as the product
|
||||||
|
if(len(nums) == 0):
|
||||||
|
return 0
|
||||||
|
|
||||||
#Setup the variables
|
#Setup the variables
|
||||||
product = 1 #Start at 1 because of working with multiplication
|
product = 1 #Start at 1 because of working with multiplication
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user