View Single Post
  #26   Report Post  
Posted to microsoft.public.excel.programming
Bruno Campanini[_2_] Bruno Campanini[_2_] is offline
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

Peter T has brought this to us :
"Bruno Campanini" wrote in message
Peter T explained :

Are you prepared to pay the same if you fail?

You have the advantage because somehow you seem to know I can't, whereas
I've never claimed I know I can. But as I think it's more than 50%
probable I can do what I said I "might" be able to do - yes.


Fantastic!
I'm prepared to pay if you success but you are not prepared to pay
the same if you fail, because you only stated "I could", "I might".

Ok, why then did you ask me if I was prepared to pay
when you were not prepared to do the same?


Read again, I said yes to your question.

Need to agree the amount, enough to make it worthwhile but can comfortably
afford to loose. Also agree in advance something like the following

1. Improve recursive speed of the function as posted for use in Excel

I stand by "perhaps" 100x but rusults would vary significantly depending on
variables such as: the length of input string, system specs, Excel version,
and other factors such how the function is called, if screenupdating is
disabled and no doubt others. Short strings wouldn't be significantly
different if even measurable.

In an older system with 2007 or earlier, with an input string of say 8+
letters returning a large number of permutations to the sheet I'd expect at
least 50x if not 100x faster or more. 64-bit Excel is much better with things
like this, I'd still expect a significant improvment but much less, still a
mutlitple order of improvement though.

The function would need to be adapted, obviously, possibly with new
arguments.

Run Test1 below to call your function, give your results with an idea of your
system specs particualrly Excel version and if Office-64. I'll then say
roughly what I'd expect to improve results by.

2. non-recursive alternative.
This is straightforward, one (or more ?) routine(s) that do not call self and
return an accurate list of all permuations of the input string.

3. As there are in effect two challenges, if I succeed in one but fail in the
other, no payment on either way.

4. Amount - suggest something

5. Time limit, suggest something reasonable to complete.

6 Other?


I understand, some times in a discussion our passion takes
our hand and makes us say more then we reasonably would.


No passions raised on my part. I tried to help, you threw it back in my face.
Even despite all that I remained polite towards you. I know nothing about you
so your arrogance and insults were of no consequence to me.


Sub Test1()
Dim s As String
Dim i As Long, t As Single
s = "ABCDE"
For i = 70 To 73
s = s & Chr$(i)
Range("A:A").ClearContents
DoEvents
t = Timer
Call Permutation(s)
t = Timer - t
Debug.Print s; " Len=" & Len(s); " Sec: " & t
Next
End Sub

Sub Permutation(Str1 As String, _
Optional Str2 As String = vbNullString, _
Optional ByRef Xrow As Long = 1)
Dim i As Integer, xLen As Integer, a As String, b As String

xLen = Len(Str1)
If xLen < 2 Then
Range("A" & Xrow) = Str2 & Str1
Xrow = Xrow + 1
Else
For i = 1 To xLen
a = Left(Str1, i - 1) & Right(Str1, xLen - i)
b = Str2 & Mid(Str1, i, 1)
Call Permutation(a, b, Xrow)
Next
End If

End Sub

Peter T


Too many words... keep calm.

All the best Peter.
Bruno