Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Recursive Code: How does it work?


The following code attributed to "big Tom" has piqued my interest but
I've failed to get my head around its mechanics-thus farl. Recursive
codes or functions call themseleves in a spiralling loop until a
defator condition is met. I understand all that and have myself set up
a few functions and codes that deploy the recursive character. But
Tom's code is one of a kind, simple and yet powerful and to draw it
mildlymore than a little mystifying. The Code is as follows (shorn of
the ByVal Refs. for simplcity):

Sub Combinations()
Dim n As Integer, m As Integer
numcomb = 0
n = InputBox("Number of items?", , 10)
m = InputBox("Taken how many at a time?", , 3)
com n, m, 1, "'"
End Sub

'Generate combinations of integers k..n taken m at a time, recursively
Sub com(n, m, k, s)
If m n - k + 1 Then Exit Sub
If m = 0 Then
ActiveCell = s
ActiveCell.Offset(1, 0).Select
Exit Sub
End If
com n, m - 1, k + 1, s & k & " "
com n, m, k + 1, s
End Sub


I should be grateful if someone that take me through why n=10, m=3
will
generate the correct 3-sized combinations from the activecell
downwards.


--
Myles
------------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=569428

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
Help with Recursive Call? mark Excel Programming 9 May 25th 06 08:44 PM
Recursive Functio help BigBobbo Excel Worksheet Functions 1 May 10th 06 07:23 PM
recursive sums Joe Excel Worksheet Functions 6 July 17th 05 09:45 AM
Recursive Subs? ExcelMonkey[_74_] Excel Programming 5 February 5th 04 02:54 AM


All times are GMT +1. The time now is 08:29 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"