Python Forum
Trying to integrate gcd function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to integrate gcd function
#1
I have this function, it prints a list of values.
def kasinski(text):
    trigraphs=[]
    distances=[]
    for trigraph in range (len(text)-2):
        newtrigraph= text[trigraph:trigraph+3]
        if newtrigraph in trigraphs:
            distances.append(trigraph-(text.index(newtrigraph)))
        else:
            trigraphs.append(newtrigraph)
            trigraphs.append(trigraph)
            return distances

I also have functions that will find the greatest common divisor of all numbers in a list
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y, x% y)
def gcd_list_helper(list, index:
    if index==len((list)-1):
        return list[index]
    else:
        return gcd(list[index], gcd_list_helper(list, index+1))
def gcd_of_list(list):
    return gcd_list_helper(list, 0)
I am having trouble integrating the gcd function into my first function so that the kasiski function returns the GCD of the list rather than the list. Any pointers?
Reply


Messages In This Thread
Trying to integrate gcd function - by hhydration - Oct-28-2020, 12:39 PM
RE: Trying to integrate gcd function - by perfringo - Oct-28-2020, 01:34 PM
RE: Trying to integrate gcd function - by perfringo - Oct-28-2020, 02:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to integrate a discontinuous function by tplquad or nquad Safinazsalem 2 202 May-29-2024, 07:22 AM
Last Post: Safinazsalem
  How to integrate this function in python symbolically Safinazsalem 0 146 May-27-2024, 12:11 PM
Last Post: Safinazsalem
  Differentiate and Integrate A Given Function wildmommy666 2 1,681 May-11-2020, 04:30 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020