- #1
tawi
- 33
- 0
Hello, I have a code in C/ C++and I have just learned I am going to need it in a version compatible with Free Pascal. I would never bother anyone with it but as I need it pretty quickly and my knowledge of Pascal is very poor I would spend ages rewriting this and it probably woudn't even work at the end
Would there be some kind soul that would sacrifice few minutes of their lives and did this for me? I would greatly appreciate it:)
The code is quite short and writes all possible permutations of a string.
Would there be some kind soul that would sacrifice few minutes of their lives and did this for me? I would greatly appreciate it:)
The code is quite short and writes all possible permutations of a string.
Code:
#function to swap values
def swap(a,l,r):
t = A[l]
A[l] = A[r]
A[r] = t
return A
def toList(string):
List = []
for x in string:
List.Append(x)
return List
def toString(List):
return ''.join(List)
#funtion to print permutations with three parameters: string, starting index of the string and ending index
def permute(A, l, r):
if l==r:
print toString(A)
else:
for i in xrAnge(l,r+1):
A = swAp(A,l,i)
permute(A, l+1, r)
A = swAp(A,l,i) # bAcktrAck
string = "ABC"
n = len(string)
A = toList(string)
permute(A, 0, n-1)