At 10:57 AM 25/11/2009, Ian Skinner wrote: >So, this problem has been sitting in my kitchen. The math has been >proved and a good solution using database table joins provided, but I >just *knew* this could be solved with looping. > >Of course it could be hard coded: ><cfoutput> > <cfloop from="0" to="1" index="a1"> > <cfloop from="0" to="1" index="a2"> > <!--- loops for a3 to a21 ---> > <cfloop from="0" to="1" index="a22"> > #yesNoFormat(a1)# #yesNoFormat(a2)# <!--- output for a3 to >a21 ---> #yesNoFormat(a22)#<br> > </cfloop> > </cfloop> > <!--- loop closes for a3 to a21 ---> > </cfloop> ></cfoutput> > >But that was too much work and this should have been solvable with >iteration. It took me a couple of days to scrape together a few free >minutes to come up with this: > ><cffunction name="it" output="yes"> > <cfargument name="depth" type="numeric" required="yes"> > <cfargument name="answerKey" type="string" required="no" default=""> > > <cfset var i = 0> > <cfif depth-- GT 0> > <cfloop from="0" to="1" index="i"> > #it(depth,answerKey & ' ' & yesNoFormat(i))# > </cfloop> > <cfelse> > #answerKey#<br/> > </cfif> ></cffunction> > ><cfoutput>#it(22)#</cfoutput> > >I leave it to somebody else to run the code to generate the 4,194,304 >combinations, but it works well up to 10 'questions'. > >
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:328671 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4