49 lines
1.3 KiB
Python
Executable File
49 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
def shift(
|
|
number,
|
|
shifts,
|
|
initialSubtraction,
|
|
currentShiftIteration,
|
|
currentSubtractionIteration,
|
|
perms):
|
|
|
|
for b in range(shifts):
|
|
if currentShiftIteration >= 4:
|
|
return
|
|
number = number << 1
|
|
currentShiftIteration += 1
|
|
perms.append([bin(number)[2:]])
|
|
initialSubtraction = (initialSubtraction << 1) + 1
|
|
subtract(number, shifts, initialSubtraction, currentShiftIteration, currentSubtractionIteration, perms[b + 1])
|
|
|
|
return
|
|
|
|
def subtract(
|
|
number,
|
|
subtractions,
|
|
initialSubtraction,
|
|
currentShiftIteration,
|
|
currentSubtractionIteration,
|
|
perms):
|
|
|
|
subtractionValue = initialSubtraction
|
|
|
|
for b in range(subtractions):
|
|
if currentSubtractionIteration >= 4:
|
|
return
|
|
number -= subtractionValue
|
|
currentSubtractionIteration += 1
|
|
subtractionValue = subtractionValue << 1
|
|
perms.append([bin(number)[2:]])
|
|
shift(number, (subtractions - 1), subtractionValue, currentShiftIteration, currentSubtractionIteration, perms[b + 1])
|
|
|
|
def run_algorithm():
|
|
permutations = ["000011111"]
|
|
shift(31, 4, 0, 0, 0, permutations)
|
|
import json
|
|
print(json.dumps(permutations, indent=4))
|
|
|
|
if __name__ == '__main__':
|
|
run_algorithm()
|