47 lines
1.0 KiB
Python
47 lines
1.0 KiB
Python
![]() |
import md5
|
||
|
|
||
|
renmich_1 = 'renmich1123376350383621786626';
|
||
|
renmich_2 = 'renmich3700873222361195459231';
|
||
|
|
||
|
def rmhash(input):
|
||
|
return md5.new(md5.new(input).digest()).digest()[1:3];
|
||
|
|
||
|
def find_colision(input):
|
||
|
tortoise=input;
|
||
|
hare=input;
|
||
|
i=0;
|
||
|
|
||
|
dlugosc_cyklu = 0;
|
||
|
pierwsze_wystapienie_cyklu = 0;
|
||
|
|
||
|
while i==0 or tortoise!=hare:
|
||
|
i+=1;
|
||
|
|
||
|
tortoise=rmhash(tortoise);
|
||
|
|
||
|
hare=rmhash(hare);
|
||
|
hare=rmhash(hare);
|
||
|
|
||
|
print("Zolw: "+tortoise+" Zajac "+hare)
|
||
|
|
||
|
#Przesuwam zajaca o jedno pole do przodu
|
||
|
hare=rmhash(hare);
|
||
|
|
||
|
while tortoise!=hare:
|
||
|
previous_hare = hare;
|
||
|
hare=rmhash(hare);
|
||
|
dlugosc_cyklu+=1;
|
||
|
|
||
|
print("Zajac jest na polu "+hare+" a byl na "+previous_hare)
|
||
|
|
||
|
#Zolw na poczatek
|
||
|
tortoise = input;
|
||
|
|
||
|
while tortoise!=hare:
|
||
|
previous_tortoise = tortoise;
|
||
|
tortoise=rmhash(tortoise);
|
||
|
pierwsze_wystapienie_cyklu+=1;
|
||
|
|
||
|
print("Zolw jest na polu "+tortoise+" a byl na "+previous_tortoise)
|
||
|
print("Dlugosc cyklu: "+str(dlugosc_cyklu))
|
||
|
print("Pierwsze wystapienie cyklu: "+str(pierwsze_wystapienie_cyklu))
|