sabertooth09

Untitled

Jun 6th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. def sol(n):
  2.     c=0
  3.     while n!=1:
  4.         if n%2==0:
  5.             n=n//2
  6.         else:
  7.             n=(3*n)+1
  8.         c=c+1
  9.     return c
  10. def swap(a,b):
  11.     temp=a
  12.     a=b
  13.     b=temp
  14.    
  15. while 1:
  16.     a,b=map(int,input().split())
  17.     if a==0 and b==0:
  18.         break
  19.     else:
  20.         x=[]
  21.         y=[]
  22.         temp=a
  23.         while temp<=b:
  24.             x.append(sol(temp))
  25.             y.append(temp)
  26.             temp+=1
  27.        
  28.         for i in range(b):
  29.             for j in range(b):
  30.                 if x[i]>x[j]:
  31.                     swap(x[i],x[j])
  32.                     swap(y[i],y[j])
  33.  
  34.                    
  35.         print(x)
  36.         print(y)
  37.         print("Between",a,"and",b,y[0],"generates the longest sequence of",x[0],"values."
  38. )
Advertisement
Add Comment
Please, Sign In to add comment