Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import itertools
- number_to_run = 312215
- def sub(a,b):
- return a - b
- def div(a,b):
- return a/b
- def mult(a,b):
- return a*b
- def last(indexes):
- return sum(indexes) == 6
- def decrease(indexes):
- bool2 = indexes[2] == 1
- bool1 = indexes[1] == 2
- if(bool1):
- indexes[0] -= 1
- indexes[1] = indexes[0] - 1
- indexes[2] = indexes[1] - 1
- return indexes
- if(bool2):
- indexes[1] -= 1
- indexes[2] = indexes[1] - 1
- return indexes
- indexes[2] -= 1
- return indexes
- def singlecomb(inputs,indexes):
- runsum = inputs
- num1 = inputs // pow(10,indexes[0])
- runsum = runsum - num1*pow(10,indexes[0])
- num2 = runsum // pow(10,indexes[1])
- runsum = runsum - num2*pow(10,indexes[1])
- num3 = runsum // pow(10,indexes[2])
- runsum = runsum - num3*pow(10,indexes[2])
- num4 = runsum
- operations = [sub, div, mult]
- smallest = inputs
- for ops in itertools.permutations(operations):
- curr_core = ops[2](ops[1](ops[0](num1,num2),num3),num4)
- if (curr_core % 1 == 0 and curr_core > 0 and curr_core <= smallest):
- smallest = curr_core
- return smallest
- def numeric_core(inputs):
- if (inputs < 999):
- return "No numeric core"
- order = math.floor(math.log10(inputs))
- smallest = inputs
- indexes = [order,order-1,order-2]
- while(not last(indexes)):
- curr = singlecomb(inputs,indexes)
- if (curr < smallest):
- smallest = curr
- indexes = decrease(indexes)
- curr = singlecomb(inputs,[3,2,1])
- if (curr < smallest):
- smallest = curr
- if (smallest > 999):
- smallest = numeric_core(smallest)
- return smallest
- print(numeric_core(number_to_run))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement