This repository has been archived on 2025-12-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
spa-paper/algorithm5.py
2013-07-17 12:35:59 -06:00

90 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
import sys
from math import factorial
def shift(
number,
set_one_size,
set_two_size,
subtractionValue,
shiftIteration,
subtractionIteration,
permutations):
for b in range(set_one_size):
if shiftIteration >= set_one_size:
return
number = number << 1
shiftIteration += 1
permutations.append(number)
subtractionValue = (subtractionValue << 1) + 1
subtract(
number,
set_one_size,
set_two_size,
subtractionValue,
shiftIteration,
subtractionIteration,
permutations)
return
def subtract(
number,
set_one_size,
set_two_size,
subtractionValue,
shiftIteration,
subtractionIteration,
permutations):
for b in range(set_two_size - 1):
if subtractionIteration >= set_two_size - 1:
return
number -= subtractionValue
subtractionIteration += 1
subtractionValue = subtractionValue << 1
permutations.append(number)
shift(
number,
set_one_size,
set_two_size,
subtractionValue,
shiftIteration,
subtractionIteration,
permutations)
def run_algorithm(set_one, set_two):
if type(set_one) != int or type(set_two) != int:
raise ValueError("Parameters were not 'int's")
num = 1
for x in range(1, set_two):
num = (num << 1) + 1
permutations = [num]
shift(permutations[0], set_one, set_two, 0, 0, 0, permutations)
# permutations.sort(key=int)
if __name__ == '__main__':
if len(sys.argv) != 3:
print(" Usage: ./algorithm4.py [set 1 count] [set 2 count]\n")
quit()
try:
set_one = int(sys.argv[1])
set_two = int(sys.argv[2])
except ValueError as e:
print("ERROR: invalid parameters. Please input numbers!")
print(" Usage: ./algorithm4.py [set 1 count] [set 2 count]\n")
quit()
run_algorithm(set_one, set_two)