Advertisement
Guest User

Core_Number_finder

a guest
Apr 14th, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import math
  2. import itertools
  3.  
  4. number_to_run = 312215
  5.  
  6. def sub(a,b):
  7. return a - b
  8.  
  9. def div(a,b):
  10. return a/b
  11.  
  12. def mult(a,b):
  13. return a*b
  14.  
  15. def last(indexes):
  16. return sum(indexes) == 6
  17.  
  18. def decrease(indexes):
  19. bool2 = indexes[2] == 1
  20. bool1 = indexes[1] == 2
  21.  
  22. if(bool1):
  23. indexes[0] -= 1
  24. indexes[1] = indexes[0] - 1
  25. indexes[2] = indexes[1] - 1
  26. return indexes
  27.  
  28. if(bool2):
  29. indexes[1] -= 1
  30. indexes[2] = indexes[1] - 1
  31. return indexes
  32.  
  33. indexes[2] -= 1
  34. return indexes
  35.  
  36. def singlecomb(inputs,indexes):
  37. runsum = inputs
  38. num1 = inputs // pow(10,indexes[0])
  39. runsum = runsum - num1*pow(10,indexes[0])
  40. num2 = runsum // pow(10,indexes[1])
  41. runsum = runsum - num2*pow(10,indexes[1])
  42. num3 = runsum // pow(10,indexes[2])
  43. runsum = runsum - num3*pow(10,indexes[2])
  44. num4 = runsum
  45.  
  46. operations = [sub, div, mult]
  47. smallest = inputs
  48.  
  49. for ops in itertools.permutations(operations):
  50. curr_core = ops[2](ops[1](ops[0](num1,num2),num3),num4)
  51. if (curr_core % 1 == 0 and curr_core > 0 and curr_core <= smallest):
  52. smallest = curr_core
  53.  
  54. return smallest
  55.  
  56.  
  57.  
  58. def numeric_core(inputs):
  59. if (inputs < 999):
  60. return "No numeric core"
  61.  
  62. order = math.floor(math.log10(inputs))
  63. smallest = inputs
  64. indexes = [order,order-1,order-2]
  65.  
  66. while(not last(indexes)):
  67. curr = singlecomb(inputs,indexes)
  68. if (curr < smallest):
  69. smallest = curr
  70. indexes = decrease(indexes)
  71.  
  72. curr = singlecomb(inputs,[3,2,1])
  73. if (curr < smallest):
  74. smallest = curr
  75. if (smallest > 999):
  76. smallest = numeric_core(smallest)
  77. return smallest
  78.  
  79. print(numeric_core(number_to_run))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement