Hi folks. I am having difficulty in coming up with the algorithm on how to take items in a list and rank them. What I'm trying to do is to create a general purpose program to do this. Around 1986, I saw this type of program listed as AppleSoft BASIC code as an appendix to that year's "What Color Is Your Parachute", but short-sightedly did not keep a copy of that program code listing. Neither the author nor the publisher of that book have the source code on file (I've already asked both of them). So, I turn to the collective wisdom and knowledge of this group for an assist. I've been struggling with coming up with this algorithm so badly for the past month that perhaps I can no longer focus on it. Here's an example of what I would like this program to accomplish... From a list of items, I'd like to be able to view only one unique pair of them at a time and pick one item from the pair. After I've made my selection, I'd like another unique pair to be presented so I can make another selection, and so on until there are no more unique pairs to be presented. During this selection process, the program would keep count of the number of times each item was selected. After all unique pairs have been presented and selections made, I'd like the program to display the results in order of most selected to least selected. My problem is not with the AppleSoft coding itself, but in determining how to go about selecting unique pairs and knowing when there are no more to be presented. Even in real life, I have difficulty knowing when to stop in such comparison activities (hence, my need to create a program to release this burden from my brain :). I would appreciate any clues as to what the algorithm may be. Thanks in advance. Steve Stephen Adams wrote: > From a list of items, I'd like to be able to view only one unique pair > of them at a time and pick one item from the pair. After I've made my > selection, I'd like another unique pair to be presented so I can make > another selection, and so on until there are no more unique pairs to be > presented. During this selection process, the program would keep count > of the number of times each item was selected. After all unique pairs > have been presented and selections made, I'd like the program to display > the results in order of most selected to least selected. > > My problem is not with the AppleSoft coding itself, but in determining > how to go about selecting unique pairs and knowing when there are no > more to be presented. Even in real life, I have difficulty knowing when > to stop in such comparison activities (hence, my need to create a > program to release this burden from my brain :). Sounds like a 2D matrix: thing1 thing2 thing3 thing4 thing1 - thing2 - thing3 - thing4 - Use the top half, e.g. if "thing3:thing2" is selected, use the thing2 row and thing3 column instead of the other way around. When you've examined ((number-of-things ^ 2) - number-of-things) / 2, you're done. For example, 4 things = ((4^2)-4)/2 = (16-4)/2 = 6. You could also just walk through the array in an obvious fashion. Adjust the above if "thing1:thing1" is considered a "unique pair". I don't actually recall whether Applesoft does N-dimensional arrays. You can just peek/poke bytes into 8192+whatever if not. Tabulating the counts requires a single-dimensional array. Producing sorted output is straightforward. -- Send mail to fadden@fadden.com (Andy McFadden) - http://www.fadden.com/ CD-Recordable FAQ - http://www.cdrfaq.org/ CiderPress Apple II archive utility for Windows - http://www.faddensoft.com/ Fight Internet Spam - http://spam.abuse.net/spam/ & http://spamcop.net/ Stephen Adams wrote: >> Use the top half, e.g. if "thing3:thing2" is selected, use the thing2 >> row and thing3 column instead of the other way around. When you've >> examined ((number-of-things ^ 2) - number-of-things) / 2, you're done. >> For example, 4 things = ((4^2)-4)/2 = (16-4)/2 = 6. You could also just >> walk through the array in an obvious fashion. > > I've done the walkthroughs for a list containing 2 items out to a list > containing 15 items. Your formula fits for those lists, so I'm > impressed! :) > > Thank you! > > Next question... how did you come up with that formula? Does one have to > have a mathematics background to see this? While I could see a recurring > "relationship" for lists containing even more items (and verified this > relationship by actually creating even more lists and counting the > unique pairs found within them), I could never hope to have put it in > the terms of such a math formula. :) I just looked at the 2D matrix (N squared in size), subtracted off the number of elements in the diagonal, and then cut the number in half since you're only using half of the array. No mathematical genius required. ;-) -- Send mail to fadden@fadden.com (Andy McFadden) - http://www.fadden.com/ CD-Recordable FAQ - http://www.cdrfaq.org/ CiderPress Apple II archive utility for Windows - http://www.faddensoft.com/ Fight Internet Spam - http://spam.abuse.net/spam/ & http://spamcop.net/ Andy McFadden wrote: >Stephen Adams wrote: >>> Use the top half, e.g. if "thing3:thing2" is selected, use the thing2 >>> row and thing3 column instead of the other way around. When you've >>> examined ((number-of-things ^ 2) - number-of-things) / 2, you're done. >>> For example, 4 things = ((4^2)-4)/2 = (16-4)/2 = 6. You could also just >>> walk through the array in an obvious fashion. >> >> I've done the walkthroughs for a list containing 2 items out to a list >> containing 15 items. Your formula fits for those lists, so I'm >> impressed! :) >> >> Thank you! >> >> Next question... how did you come up with that formula? Does one have to >> have a mathematics background to see this? While I could see a recurring >> "relationship" for lists containing even more items (and verified this >> relationship by actually creating even more lists and counting the >> unique pairs found within them), I could never hope to have put it in >> the terms of such a math formula. :) > >I just looked at the 2D matrix (N squared in size), subtracted off the >number of elements in the diagonal, and then cut the number in half since >you're only using half of the array. No mathematical genius required. ;-) Stephen, by comparison, think of a "distance chart" of the distances between all unique pairs of a list of cities. In fact, your "ranking" is just such a distance chart. -michael Check out amazing quality sound for 8-bit Apples on my Home page: http://members.aol.com/MJMahon/ Stephen Adams wrote: > Hi folks. > > I am having difficulty in coming up with the algorithm on how to take > items in a list and rank them. What I'm trying to do is to create a > general purpose program to do this. Around 1986, I saw this type of > program listed as AppleSoft BASIC code as an appendix to that year's > "What Color Is Your Parachute", but short-sightedly did not keep a copy > of that program code listing. Neither the author nor the publisher of > that book have the source code on file (I've already asked both of them). [...] > I would appreciate any clues as to what the algorithm may be. Thanks in > advance. For interesting reading, and to help you think more about problems like these, try this book: "Programming Pearls", by Jon Bentley It might get you thinking in new ways about how to visualize and solve various problems like the one you mention. -- Jerry Penner e-mail: remove blip and _