Skip to content

Commit

Permalink
added permutations program
Browse files Browse the repository at this point in the history
  • Loading branch information
NinjaTyper committed Jul 5, 2023
1 parent 0c3934a commit b668823
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions peter/permutations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Entry:
def __init__(self, frontArray, backArray) -> None:
self.frontArray = frontArray
self.backArray = backArray



class Permu:
def __init__(self, array) -> None:
self.array = array
self.bucket = []

def print_all(self):
firstEntry = Entry([], self.array.copy())
self.bucket.append(firstEntry)

while len(self.bucket) > 0:
current = self.bucket.pop(0)
if len(current.backArray) == 0:
print(current.frontArray)
else:
for i in range(len(current.backArray)):
newEntry = Entry(current.frontArray.copy(), current.backArray.copy())
newEntry.frontArray.append(current.backArray[i])
newEntry.backArray.pop(i)
self.bucket.append(newEntry)


def basictest1():
inputString = input("give an array: ")
inputArray = inputString.split(" ")
permu = Permu(inputArray)
permu.print_all()

if __name__ == "__main__":
basictest1()

0 comments on commit b668823

Please sign in to comment.