Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

Can anybody convert this recursive procedure to a non-recursive one?
========================================
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
========================================

The procedure is called, in the simplest way, with:
Call Permutation("string-to-permute").

Bruno
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Recursive To non-Recursive Procedure

Bruno Campanini wrote:

Can anybody convert this recursive procedure to a non-recursive one?


[snip]

The procedure is called, in the simplest way, with:
Call Permutation("string-to-permute").


On the one hand, yes, it can be unrolled, using some combination of control
structures.

On the other hand, *why* do you want it to be unrolled?

--
I am invincible, INVINCIBLE I say! *laughs*
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

Auric__ formulated the question :
Bruno Campanini wrote:

Can anybody convert this recursive procedure to a non-recursive one?


[snip]

The procedure is called, in the simplest way, with:
Call Permutation("string-to-permute").


On the one hand, yes, it can be unrolled, using some combination of control
structures.

On the other hand, *why* do you want it to be unrolled?


Why you ask me that?

Bruno
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Recursive To non-Recursive Procedure

Bruno Campanini wrote:

Auric__ formulated the question :
Bruno Campanini wrote:

Can anybody convert this recursive procedure to a non-recursive one?


[snip]

The procedure is called, in the simplest way, with:
Call Permutation("string-to-permute").


On the one hand, yes, it can be unrolled, using some combination of
control structures.

On the other hand, *why* do you want it to be unrolled?


Why you ask me that?


It's pretty straightforward: What is the purpose of unrolling the recursive
procedure you posted? What are you trying to accomplish?

Here's a Google search that'll get you started:

https://www.google.com/search?q=stri...+non-recursive

--
Better to die quick, fighting on your feet,
than to live forever, begging on your knees.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

Auric__ brought next idea :
Bruno Campanini wrote:

Auric__ formulated the question :
Bruno Campanini wrote:

Can anybody convert this recursive procedure to a non-recursive one?

[snip]

The procedure is called, in the simplest way, with:
Call Permutation("string-to-permute").

On the one hand, yes, it can be unrolled, using some combination of
control structures.

On the other hand, *why* do you want it to be unrolled?


Why you ask me that?


It's pretty straightforward: What is the purpose of unrolling the recursive
procedure you posted? What are you trying to accomplish?

There is an algorithm:
a = Left(Str1, i - 1) & Right(Str1, xLen - i)
b = Str2 & Mid(Str1, i, 1)
Call Permutation(a, b, Xrow)
which is well known to the net, whose author is unknown to the net.
It's very simple and efficient and I'd like to preserve in a
non-recursive procedure.
But I am not able to make the conversion.

Here's a Google search that'll get you started:
https://www.google.com/search?q=stri...+non-recursive

Really I don't need that.

Bruno


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Recursive To non-Recursive Procedure

"Bruno Campanini" wrote in message
On the other hand, *why* do you want it to be unrolled?

Why you ask me that?


You seem reluctant to give a reason. Is this homework to find a less elegant
non-recursive alternative as an exercise?

Here's a Google search that'll get you started:
https://www.google.com/search?q=stri...+non-recursive

Really I don't need that.


Why not? I found several potential solutions in a few minutes.

Peter T




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

Peter T formulated the question :
"Bruno Campanini" wrote in message
On the other hand, *why* do you want it to be unrolled?

Why you ask me that?


You seem reluctant to give a reason. Is this homework to find a less elegant
non-recursive alternative as an exercise?

Here's a Google search that'll get you started:
https://www.google.com/search?q=stri...+non-recursive

Really I don't need that.


Why not? I found several potential solutions in a few minutes.

Oh... you are a very clever man, congratulation!
Why don't you read accurately before writing?

I don't need any practical solution, it's only a matter of
principle.
I would be able to convert that particular algorithm into a
non-recursive procedure, but I'm unable to do so.
Then I put here the question.

Have I satisfied your curiosity?

Bruno
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Recursive To non-Recursive Procedure


"Bruno Campanini" wrote in message
Peter T formulated the question :
"Bruno Campanini" wrote in message
On the other hand, *why* do you want it to be unrolled?

Why you ask me that?


You seem reluctant to give a reason. Is this homework to find a less
elegant non-recursive alternative as an exercise?

Here's a Google search that'll get you started:
https://www.google.com/search?q=stri...+non-recursive
Really I don't need that.


Why not? I found several potential solutions in a few minutes.

Oh... you are a very clever man, congratulation!
Why don't you read accurately before writing?

I don't need any practical solution, it's only a matter of
principle.
I would be able to convert that particular algorithm into a
non-recursive procedure, but I'm unable to do so.
Then I put here the question.

Have I satisfied your curiosity?


Not really a matter of curiosity, often asking the objective leads to a
different approach the OP might not have considered, particularly when the
reason for the question is not clear. So it's a sort of intellectual
exercise then, right?

Although any approach will end up doing essentially the same thing your
algorithm is not directly convertible as it's designed to be recursive.

Oh... you are a very clever man, congratulation!


Huh, it was a simple search, why the sarcasm, why not try yourself!

Why don't you read accurately before writing?


AFAIK I did read accurately before posting. Not sure why you're so
aggressive to people who try to help you.

Peter T


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

Peter T explained :
"Bruno Campanini" wrote in message
Peter T formulated the question :
"Bruno Campanini" wrote in message
On the other hand, *why* do you want it to be unrolled?

Why you ask me that?

You seem reluctant to give a reason. Is this homework to find a less
elegant non-recursive alternative as an exercise?

Here's a Google search that'll get you started:
https://www.google.com/search?q=stri...+non-recursive
Really I don't need that.

Why not? I found several potential solutions in a few minutes.

Oh... you are a very clever man, congratulation!
Why don't you read accurately before writing?

I don't need any practical solution, it's only a matter of
principle.
I would be able to convert that particular algorithm into a
non-recursive procedure, but I'm unable to do so.
Then I put here the question.

Have I satisfied your curiosity?


Not really a matter of curiosity, often asking the objective leads to a
different approach the OP might not have considered, particularly when the
reason for the question is not clear. So it's a sort of intellectual exercise
then, right?

Although any approach will end up doing essentially the same thing your
algorithm is not directly convertible as it's designed to be recursive.

Any recursive algorithm is convertible into a non-recursive one...
and vice-versa!
The cost may be a great difficulty, a loss of simplicity, a loss
of efficiency.

Oh... you are a very clever man, congratulation!

Huh, it was a simple search, why the sarcasm, why not try yourself!

Such a simple search that I tried just before you was born!

Why don't you read accurately before writing?

AFAIK I did read accurately before posting. Not sure why you're so aggressive
to people who try to help you.

Not to all people, only to all who:
- didn't understand the question
- doesn't have an idea about the solution.
- doesn't hesitate to spend unuseful words... as it costs nothing!

Bruno
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Recursive To non-Recursive Procedure

"Bruno Campanini" wrote in message
Peter T explained

:
"Bruno Campanini" wrote in message
Peter T formulated the question :
"Bruno Campanini" wrote in message
On the other hand, *why* do you want it to be unrolled?

Why you ask me that?

You seem reluctant to give a reason. Is this homework to find a less
elegant non-recursive alternative as an exercise?

Here's a Google search that'll get you started:
https://www.google.com/search?q=stri...+non-recursive
Really I don't need that.

Why not? I found several potential solutions in a few minutes.
Oh... you are a very clever man, congratulation!
Why don't you read accurately before writing?

I don't need any practical solution, it's only a matter of
principle.
I would be able to convert that particular algorithm into a
non-recursive procedure, but I'm unable to do so.
Then I put here the question.

Have I satisfied your curiosity?


Not really a matter of curiosity, often asking the objective leads to a
different approach the OP might not have considered, particularly when
the reason for the question is not clear. So it's a sort of intellectual
exercise then, right?

Although any approach will end up doing essentially the same thing your
algorithm is not directly convertible as it's designed to be recursive.

Any recursive algorithm is convertible into a non-recursive one...
and vice-versa!


Some recursive routines can be 'converted' to non-recursive using
essentially the same algorithm inside an additional loop. However I don't
see an obvious way that can be done with your particular algorithm. So it
means devising a different approach, or instead of re-inventing the wheel
search as suggested and adapt what best suits the particular objective.

The cost may be a great difficulty, a loss of simplicity, a loss
of efficiency.


Typically no significant difference in efficiency, if anything non-recursive
may be slightly more efficient (in terms of speed) even if less elegant.

Oh... you are a very clever man, congratulation!

Huh, it was a simple search, why the sarcasm, why not try yourself!

Such a simple search that I tried just before you was born!

Why don't you read accurately before writing?

AFAIK I did read accurately before posting. Not sure why you're so
aggressive to people who try to help you.

Not to all people, only to all who:
- didn't understand the question
- doesn't have an idea about the solution.
- doesn't hesitate to spend unuseful words... as it costs nothing!


I don't know what your problem is. I've answered 1000s of question in this
group going back since before MS adopted it, but rarely come across an
attitude like yours.

I thought I understood your question, then your replies to Auric confused
me, I didn't understand why his suggestion wasn't helpful and your
reluctance to give a reason didn't help. Hence I tried to get a better idea
of your overall objective before wasting time on something you didn't want.

I use recursive functions extensively and already knew your algorithm,
though FWIW the particular implementation you posted is inefficient for
Excel with an input of any more than a few letters.

Peter T




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

Peter T was thinking very hard :
"Bruno Campanini" wrote in message
Peter T explained

:
"Bruno Campanini" wrote in message
Peter T formulated the question :
"Bruno Campanini" wrote in message
On the other hand, *why* do you want it to be unrolled?

Why you ask me that?

You seem reluctant to give a reason. Is this homework to find a less
elegant non-recursive alternative as an exercise?

Here's a Google search that'll get you started:
https://www.google.com/search?q=stri...+non-recursive
Really I don't need that.

Why not? I found several potential solutions in a few minutes.
Oh... you are a very clever man, congratulation!
Why don't you read accurately before writing?

I don't need any practical solution, it's only a matter of
principle.
I would be able to convert that particular algorithm into a
non-recursive procedure, but I'm unable to do so.
Then I put here the question.

Have I satisfied your curiosity?

Not really a matter of curiosity, often asking the objective leads to a
different approach the OP might not have considered, particularly when
the reason for the question is not clear. So it's a sort of intellectual
exercise then, right?

Although any approach will end up doing essentially the same thing your
algorithm is not directly convertible as it's designed to be recursive.

Any recursive algorithm is convertible into a non-recursive one...
and vice-versa!


Some recursive routines can be 'converted' to non-recursive using essentially
the same algorithm inside an additional loop. However I don't see an obvious
way that can be done with your particular algorithm. So it means devising a
different approach, or instead of re-inventing the wheel search as suggested
and adapt what best suits the particular objective.

The cost may be a great difficulty, a loss of simplicity, a loss
of efficiency.


Typically no significant difference in efficiency, if anything non-recursive
may be slightly more efficient (in terms of speed) even if less elegant.

Oh... you are a very clever man, congratulation!
Huh, it was a simple search, why the sarcasm, why not try yourself!

Such a simple search that I tried just before you was born!

Why don't you read accurately before writing?
AFAIK I did read accurately before posting. Not sure why you're so
aggressive to people who try to help you.

Not to all people, only to all who:
- didn't understand the question
- doesn't have an idea about the solution.
- doesn't hesitate to spend unuseful words... as it costs nothing!


I don't know what your problem is. I've answered 1000s of question in this
group going back since before MS adopted it, but rarely come across an
attitude like yours.

I thought I understood your question, then your replies to Auric confused me,
I didn't understand why his suggestion wasn't helpful and your reluctance to
give a reason didn't help. Hence I tried to get a better idea of your overall
objective before wasting time on something you didn't want.

I use recursive functions extensively and already knew your algorithm, though
FWIW the particular implementation you posted is inefficient for Excel with
an input of any more than a few letters.


My final conclusion:
- I have a problem we (you and me) are unable to solve
- You like chatting, I don't like it.

Have a good day.
Bruno
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 151
Default Recursive To non-Recursive Procedure

FWIW I reckon all you good folk who give of not only your knowledge, but also your time are awesome.

You have helped and got me on the right track on many occasions and am extremely grateful & thankful.

Maybe poor Bruno needs a Group Hug to help him feel better.. :)

I always taught my children & grandchildren the philosophy that you will always attract more ants with honey than with vinegar.

Cheers
Mark.
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Recursive To non-Recursive Procedure

"Living the Dream" wrote in message
FWIW I reckon all you good folk who give of not only your knowledge, but
also your time are awesome.

You have helped and got me on the right track on many occasions and am
extremely grateful & thankful.

Maybe poor Bruno needs a Group Hug to help him feel better.. :)


LOL!

Silly thing is I might have given him an example of what I think he was
looking for, and suggested how he could speed up his original function (for
use in Excel) perhaps by 100x

I always taught my children & grandchildren the philosophy that you will
always attract more ants with honey than with vinegar.


Indeed :)

Peter T


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

Peter T explained on 11-08-17 :
"Living the Dream" wrote in message
FWIW I reckon all you good folk who give of not only your knowledge, but
also your time are awesome.

You have helped and got me on the right track on many occasions and am
extremely grateful & thankful.

Maybe poor Bruno needs a Group Hug to help him feel better.. :)


LOL!

Silly thing is I might have given him an example of what I think he was
looking for, and suggested how he could speed up his original function (for
use in Excel) perhaps by 100x


I challenge you to do that!
Don't let me think you are a liar.

Bruno
  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

Living the Dream pretended :
FWIW I reckon all you good folk who give of not only your knowledge, but also
your time are awesome.

You have helped and got me on the right track on many occasions and am
extremely grateful & thankful.

Love is a many splendored thing...

Maybe poor Bruno needs a Group Hug to help him feel better.. :)

Maybe not...

I always taught my children & grandchildren the philosophy that you will
always attract more ants with honey than with vinegar.

If you are a philosopher then Plato was a plumber!

What a disaster has been Internet, all people allowed to write.
Using icons like stupid children!

Bruno


  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Recursive To non-Recursive Procedure


"Bruno Campanini" wrote in message
LOL!

Silly thing is I might have given him an example of what I think he was
looking for, and suggested how he could speed up his original function
(for use in Excel) perhaps by 100x


I challenge you to do that!
Don't let me think you are a liar.


That's two challenges, significantly speed up your recursive routine as
posted and come up with a non-recursive alternative.

I could probably do both or I wouldn't have said so. But if you think I'm
going to spend time working on examples for someone with such an awful
attitude towards people you don't know who tried to help you think again. It
is of no concern to me if you want to think I am a liar.

You made the challenges so propose what you will pay if I can demonstrate
what I suggested. If it's meaningful I'll have a go. Your call.

Peter T


  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

Peter T explained on 13-08-17 :
"Bruno Campanini" wrote in message
LOL!

Silly thing is I might have given him an example of what I think he was
looking for, and suggested how he could speed up his original function
(for use in Excel) perhaps by 100x


I challenge you to do that!
Don't let me think you are a liar.


That's two challenges, significantly speed up your recursive routine as
posted and come up with a non-recursive alternative.

I could probably do both or I wouldn't have said so. But if you think I'm
going to spend time working on examples for someone with such an awful
attitude towards people you don't know who tried to help you think again. It
is of no concern to me if you want to think I am a liar.

You made the challenges so propose what you will pay if I can demonstrate
what I suggested. If it's meaningful I'll have a go. Your call.


Are you prepared to pay the same if you fail?

Bruno
  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Recursive To non-Recursive Procedure

Are you prepared to pay the same if you fail?

Bruno


Since I already know Peter can do this, I propose prepayment by you for the
solution. Don't worry about validation because many of the regulars here will
handle that for you because clearly your attitude has earned a great deal of
mistrust here!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Recursive To non-Recursive Procedure


"GS" wrote in message
Are you prepared to pay the same if you fail?

Bruno


Since I already know Peter can do this, I propose prepayment by you for
the solution. Don't worry about validation because many of the regulars
here will handle that for you because clearly your attitude has earned a
great deal of mistrust here!


Do you know that - I appreciate your confidence:)

So Bruno knows I can't, you know I can, the only one who has not made a
definite claim I know either way is me!

All I said was I "might" be able to come up with a non-recursive alternative
and speed up his recursive "perhaps" by 100x.

Peter T


  #20   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Recursive To non-Recursive Procedure

"GS" wrote in message
Are you prepared to pay the same if you fail?

Bruno


Since I already know Peter can do this, I propose prepayment by you for the
solution. Don't worry about validation because many of the regulars here
will handle that for you because clearly your attitude has earned a great
deal of mistrust here!


Do you know that - I appreciate your confidence:)

So Bruno knows I can't, you know I can, the only one who has not made a
definite claim I know either way is me!

All I said was I "might" be able to come up with a non-recursive alternative
and speed up his recursive "perhaps" by 100x.

Peter T


I was basing my assertion on our history! Frankly, though, I wouldn't waste the
time unless you really wanted to give it a shot...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #21   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Recursive To non-Recursive Procedure


"Bruno Campanini" wrote in message
Peter T explained on 13-08-17 :
"Bruno Campanini" wrote in message
LOL!

Silly thing is I might have given him an example of what I think he was
looking for, and suggested how he could speed up his original function
(for use in Excel) perhaps by 100x

I challenge you to do that!
Don't let me think you are a liar.


That's two challenges, significantly speed up your recursive routine as
posted and come up with a non-recursive alternative.

I could probably do both or I wouldn't have said so. But if you think I'm
going to spend time working on examples for someone with such an awful
attitude towards people you don't know who tried to help you think again.
It is of no concern to me if you want to think I am a liar.

You made the challenges so propose what you will pay if I can demonstrate
what I suggested. If it's meaningful I'll have a go. Your call.


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.

Peter T


  #22   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Recursive To non-Recursive Procedure


"GS" wrote in message
"GS" wrote in message
Are you prepared to pay the same if you fail?

Bruno

Since I already know Peter can do this, I propose prepayment by you for
the solution. Don't worry about validation because many of the regulars
here will handle that for you because clearly your attitude has earned a
great deal of mistrust here!


Do you know that - I appreciate your confidence:)

So Bruno knows I can't, you know I can, the only one who has not made a
definite claim I know either way is me!

All I said was I "might" be able to come up with a non-recursive
alternative and speed up his recursive "perhaps" by 100x.

Peter T


I was basing my assertion on our history! Frankly, though, I wouldn't
waste the time unless you really wanted to give it a shot...


As I've already said I'm certainly not going to waste my time unless he
wants to pay for it. If he does I'll give it a shot.

Peter T


  #23   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

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?
I understand, some times in a discussion our passion takes
our hand and makes us say more then we reasonably would.

Well, that said and forgotten... are you prepared to restart
discussion from the beginning?

Bruno
  #24   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Recursive To non-Recursive Procedure

GS wrote:
Are you prepared to pay the same if you fail?

Bruno


Since I already know Peter can do this, I propose prepayment by you for the
solution. Don't worry about validation because many of the regulars here will
handle that for you because clearly your attitude has earned a great deal of
mistrust here!


Why don't you switch your brain on before talking|writing?

Bruno
  #25   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Recursive To non-Recursive Procedure


"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




  #26   Report Post  
Posted to microsoft.public.excel.programming
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
  #27   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 151
Default Recursive To non-Recursive Procedure

A..HaHaHa...

Oh my, your parents must be bursting with pride at the kind, polite son they have raised.

Meh, as for your comments, whatever sunshine! needless to say, and i'm fairly certain I echo many here by now, I'm thinking you will find it somewhat challenging to garner any responses to future posting within this group.

Adieu my poor ignorant friend.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive Functions...maybe busboy10 Excel Worksheet Functions 0 March 28th 11 09:46 PM
Is this a recursive problem? davegb Excel Programming 2 August 16th 06 07:53 PM
Recursive Code Myles[_68_] Excel Programming 1 August 13th 06 02:11 PM
Help with Recursive Call? mark Excel Programming 9 May 25th 06 08:44 PM


All times are GMT +1. The time now is 08:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"