50 lines
1.4 KiB
Python
Executable File
50 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
def shift(
|
|
number,
|
|
shifts,
|
|
initialSubtraction,
|
|
currentShiftIteration,
|
|
currentSubtractionIteration,
|
|
permutations):
|
|
|
|
for b in range(shifts):
|
|
if currentShiftIteration >= 4:
|
|
return
|
|
number = number << 1
|
|
currentShiftIteration += 1
|
|
permutations.append(number)
|
|
initialSubtraction = (initialSubtraction << 1) + 1
|
|
subtract(number, shifts, initialSubtraction, currentShiftIteration, currentSubtractionIteration, permutations)
|
|
|
|
return
|
|
|
|
def subtract(
|
|
number,
|
|
subtractions,
|
|
initialSubtraction,
|
|
currentShiftIteration,
|
|
currentSubtractionIteration,
|
|
permutations):
|
|
|
|
subtractionValue = initialSubtraction
|
|
|
|
for b in range(subtractions):
|
|
if currentSubtractionIteration >= 4:
|
|
return
|
|
number -= subtractionValue
|
|
currentSubtractionIteration += 1
|
|
subtractionValue = subtractionValue << 1
|
|
permutations.append(number)
|
|
shift(number, (subtractions - 1), subtractionValue, currentShiftIteration, currentSubtractionIteration, permutations)
|
|
|
|
def run_algorithm():
|
|
permutations = [31]
|
|
shift(permutations[0], 4, 0, 0, 0, permutations)
|
|
# permutations.sort(key=int)
|
|
print(permutations)
|
|
print(len(permutations))
|
|
|
|
if __name__ == '__main__':
|
|
run_algorithm()
|