Guest User

Untitled

a guest
Mar 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #!usr/bin/env python3
  2. """
  3. This script is the r/DailyProgrammer Easy Challenge #354 titled
  4. Integer Complexity 1.
  5. Author: Christopher Bilger
  6. """
  7. import math as Math
  8.  
  9.  
  10. class Integer():
  11. """
  12. This class handles the calculations involving the input integer.
  13. """
  14. def __init__(self, integer):
  15. self.integer = integer
  16. self.multiples = []
  17.  
  18. for factor in range(1, Math.floor(integer/2)):
  19. if integer % factor == 0:
  20. self.multiples.append(factor+(integer/factor))
  21.  
  22. def get_smallest_multiple(self):
  23. """
  24. Getter method for the smallest integer in the Integer.multiples list
  25. @return int Smallest integer in the list
  26. """
  27. if len(self.multiples) == 0:
  28. return 0
  29. elif len(self.multiples) == 1:
  30. return int(self.multiples[0])
  31.  
  32. smallest = self.multiples[0]
  33. for index in range(1, len(self.multiples)):
  34. if self.multiples[index] < smallest:
  35. smallest = self.multiples[index]
  36.  
  37. return int(smallest)
  38.  
  39.  
  40. def main():
  41. """
  42. The main method that will be executed and will print out
  43. the smallest integers.
  44. """
  45. print("4567 | " + str(Integer(4567).get_smallest_multiple()))
  46. print("12345 | " + str(Integer(12345).get_smallest_multiple()))
  47. print("345678 | " + str(Integer(345678).get_smallest_multiple()))
  48.  
  49.  
  50. if __name__ == '__main__':
  51. main()
Add Comment
Please, Sign In to add comment