From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c42dbf68f5320193 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-07 22:24:08 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!207.115.63.138!newscon04.news.prodigy.com!newsmst01.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr13.news.prodigy.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Generation of permutations References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 67.115.107.194 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr13.news.prodigy.com 1020835414 ST000 67.115.107.194 (Wed, 08 May 2002 01:23:34 EDT) NNTP-Posting-Date: Wed, 08 May 2002 01:23:34 EDT Organization: Prodigy Internet http://www.prodigy.com X-UserInfo1: OH\IRYOGTRUSP_@YMZJ\_Q\@TJ_ZTB\MV@BT]UEK@YUDUWYAKVUOPCW[ML\JXUCKVFDYZKBMSFX^OMSAFNTINTDDMVW[X\THOPXZRVOCJTUTPC\_JSBVX\KAOTBAJBVMZTYAKMNLDI_MFDSSOLXINH__FS^\WQGHGI^C@E[A_CF\AQLDQ\BTMPLDFNVUQ_VM Date: Wed, 08 May 2002 05:23:35 GMT Xref: archiver1.google.com comp.lang.ada:23697 Date: 2002-05-08T05:23:35+00:00 List-Id: > start running at instruction 0. Did the data set on disk get sorted? No? Go > back to filling memory again. >... >So did the program get stuck in an infinite loop or is it just taking a >*really* long time to sort the data? As Dewar points out, you just keep snapshots of all the states the program has gone through and check for "Hey! We've been here before!". Your RAM + disk have a finite number of bits N so there are at most 2**N possible states it can wander among. If the instruction execution time is t, it can't run more than t*2**N without repeating itself. Or you can calculate how long T some standard sort algorithm would take, maximum, then abort if your randomly generated program is still running at T+1 sec. If your random program generator will create all possible configurations of RAM, then one of those is going to be identical to the standard sort algorithm and eventually you are going to come across it, guaranteed. If there are N bits in RAM, this is guaranteed to take no more than (T+1)*2**N. And you may get lucky and find a better random program sooner. Slow, yes, but not interminable. ;) > assuming that one of the rules of slow sorting is that you > guarantee the algorithm will eventually result in a sorted list of data. If no individual random program is allowed to run forever, and your random generator generates all possible programs in your finite machine, then loop generate random program; run it till done or it's in a loop or it's been running T seconds; exit when sorted; end loop; is indeed guaranteed to sort your data in a finite, albeit long, time. You can do a similar thing to generate a general sort program. loop generate random program; appears_successful := true; for all possible sets of data on your disk loop run it till done or it's in a loop or it's been running T seconds; if not data_is_sorted then appears_successful := false; exit; end if; end loop; exit when appears_successful; end loop; This too must terminate in a finite time, giving you a general sort program that will work on any set of data on your disk.