guitar-player

same_digits_number_and_multiples.py

May 27th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. '''
  2. *******************************************************************************
  3. * Written by I.F. Luis Mex Dzib 1/May/2014
  4. * krtk_140989<at>hotmail<dot>com
  5. * This program Solve the following:...
  6. It can be seen that the number, 125874, and its double, 251748,
  7. contain exactly the same digits, but in a different order.
  8. Find the smallest positive integer, x, such that 2x,
  9. 3x, 4x, 5x, and 6x, contain the same digits.'''
  10.  
  11. def contiene(numero,mult):
  12.     numeros     = []
  13.     comparacion = []
  14.     cad_numero  = str(numero)
  15.     cad_mult    = str(numero*mult)
  16.    
  17.     if (len(cad_numero) < len(cad_mult)):
  18.         return False
  19.  
  20.     for i in range(0,len(cad_numero)):
  21.         numeros.append(int(cad_numero[i]))
  22.         comparacion.append(int(cad_mult[i]))
  23.        
  24.     numeros.sort()
  25.     comparacion.sort()
  26.    
  27.     i = 0
  28.     while True:
  29.         if i >= len(numeros): break
  30.         if numeros[i] != comparacion[i]:
  31.             return False
  32.         elif numeros[i] == comparacion[i]:
  33.             i+=1
  34.    
  35.     return True
  36.  
  37. cont   = 0
  38. numero = 1
  39. _max   = 6
  40.  
  41. while True:
  42.     if cont >= _max:
  43.         break
  44.    
  45.     if contiene(numero,2):
  46.         for i in range(3,_max+1):
  47.             if contiene(numero,i) == False :
  48.                 cont = 0
  49.                 numero+=1
  50.             else:
  51.                 cont+=1
  52.     else:
  53.         numero+=1
  54.  
  55. for m in range(2,_max+1):
  56.     print numero,contiene(numero,m),m,"x",m*numero
Advertisement
Add Comment
Please, Sign In to add comment