91 lines
1.7 KiB
Python
91 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Sat Nov 2 12:27:26 2019
|
|
|
|
@author: suwako
|
|
"""
|
|
|
|
|
|
def estEgyptienne(lst):
|
|
last = lst[0]
|
|
for element in lst[1:]:
|
|
print(element,last)
|
|
if element <= last or last < 2:
|
|
return False
|
|
last = element
|
|
return True
|
|
|
|
|
|
def rationnel(lst):
|
|
p, q = 0, 1
|
|
for i in range(len(lst)):
|
|
q *= lst[i]
|
|
reduite = lst[:i]+lst[i+1:]
|
|
terme = 1
|
|
for element in reduite:
|
|
terme *= element
|
|
p += terme
|
|
return (p, q)
|
|
|
|
def fractionEgyptienne(p, q):
|
|
a = p
|
|
b = q
|
|
lst=[]
|
|
while b % a != 0:
|
|
print(a, b, lst)
|
|
m = b // a + 1
|
|
lst.append(m)
|
|
a = a * m - b
|
|
b = b * m
|
|
print(a, b, lst)
|
|
lst.append(b // a)
|
|
return lst
|
|
|
|
|
|
def estPrefixe(u, v):
|
|
if len(v) > len(u):
|
|
return False
|
|
for i in range(len(v)):
|
|
if u[i] != v[i]:
|
|
return False
|
|
return True
|
|
|
|
|
|
def bord(u):
|
|
for i in range(1, len(u)):
|
|
if estPrefixe(u, u[i:]):
|
|
return u[i:]
|
|
return ""
|
|
|
|
|
|
def Bords(u):
|
|
lst = [None]
|
|
for k in range(1, len(u) + 1):
|
|
lst.append(len(bord(u[:k])))
|
|
return lst
|
|
|
|
|
|
def estFacteur(u, v):
|
|
for i in range(len(u)-len(v) + 1):
|
|
if estPrefixe(u[i:i+len(v)], v):
|
|
return True
|
|
return False
|
|
|
|
|
|
def estFacteurMP(u, v):
|
|
bords = Bords(v)
|
|
i=0
|
|
while i <= len(u) - len(v):
|
|
skip=False
|
|
for j in range(len(v)):
|
|
print(i, j)
|
|
if u[i+j]!=v[j]:
|
|
i += bords[j+1] + 1
|
|
skip=True
|
|
break
|
|
if skip:
|
|
continue
|
|
return True
|
|
return False
|
|
|