<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">I had made a previous post on this subject and have spent a few days trying to work out this problem but I feel like I have hit a dead end, and I am hoping I can get some advice from a few people with more experience than I.<br><br>The code I have managed to create so far is:<br>(define(find-div n i)<br> (cond<br> [(=(remainder n i)0)i]<br> [else(find-div n(sub1 i))]))<br>;(find-div 20 3)<br><br>(define(tabulate-div n)<br> (cond<br> [(= n 1)(list 1)]<br> [else(append<br> (cons n empty)<br> (tabulate-div(find-div n(sub1 n))))]))<br>(tabulate-div 20)<br><br>I believe that I understand how generative recursion, and I have spent a lot of time attempting to figure this problem
out in a much more complex way. The above code seems much easier to read and understand, but, it suffers similar problems as the other things I have tried. Mainly, it doesn't produced the wanted answer, it's close, but not quite there. <br><br>(tabulate-div 20) should equal (list 1 2 4 5 10 20)<br>However, with this code the answer given is (list 20 10 5 1). <br>I have figured out that if I somehow divide 20 by each number in the list I get<br>(list(/ 20 20)(/ 20 10)(/ 20 5)(/ 20 1))=(list 1 2 4 20) which seems a little closer, but still not quite there. Although this would only be close and not all the way there, I feel its a step in the right direction. My problem is that if I add a local definition of:<br>(local((define q(/ n (find-div n n))))<br>it produces an incorrect answer. This would give me(list(/ 20 20)(/ 10 10)(/ 5 5)(/ 1 1))<br><br>Maybe I don't understand how generative recursion works exactly. I could really use some advice, this problem
is starting to aggravate me.<br><br></td></tr></table><br>