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-Thread: 103376,7255bf4b86d6b125 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,CP1252 Path: g2news1.google.com!news3.google.com!news4.google.com!news.glorb.com!newspeer1.se.telia.net!se.telia.net!masternews.telia.net.!newsb.telia.net.POSTED!not-for-mail From: =?windows-1252?Q?Bj=F6rn_Persson?= User-Agent: Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: help with starting a program (newbie) References: <1140126464.020101.55150@o13g2000cwo.googlegroups.com> <1140193368.725447.184020@g44g2000cwa.googlegroups.com> <1140199513.110445.267520@g44g2000cwa.googlegroups.com> In-Reply-To: <1140199513.110445.267520@g44g2000cwa.googlegroups.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <9rtJf.45284$d5.201678@newsb.telia.net> Date: Fri, 17 Feb 2006 23:59:01 GMT NNTP-Posting-Host: 83.250.106.90 X-Complaints-To: abuse@telia.com X-Trace: newsb.telia.net 1140220741 83.250.106.90 (Sat, 18 Feb 2006 00:59:01 CET) NNTP-Posting-Date: Sat, 18 Feb 2006 00:59:01 CET Organization: Telia Internet Xref: g2news1.google.com comp.lang.ada:2945 Date: 2006-02-17T23:59:01+00:00 List-Id: You seem to be on the right track. What's missing is mostly the code for printing the chains when they're found. Your approach seems to be that for each number in the range you calculate a sequence of sums of divisors and see whether it wraps around before it exceeds the maximum length. This might not be the fastest method and it will find the same chain multiple times, but I see that the sample run you posted does list the same chains multiple times, so apparenty this is acceptable. > Minnumber : Natural range 0 .. Integer'Last; This is exactly the same as "Minnumber : Natural;". > Maxnumber : Natural range Minnumber .. Integer'Last; You're trying to codify that Maxnumber must not be less than Minnumber. This is not a bad idea, but then you have to know the value of Minnumber before you can declare Maxnumber. You have to do it like this: procedure Sociablechain is -- other code here Minnumber : Natural; -- We can't reference Minnumber yet. begin Put(Item => " Please enter your starting integer. "); Get(Item => Minnumber); New_Line; declare -- Now Minnumber has a value. Maxnumber : Natural range Minnumber .. Integer'Last; begin Put(Item => " Please enter your ending integer. "); Get(Item => Maxnumber); New_Line; -- other code here end; end Sociablechain; > Length : Natural range 1 .. 30; Is it specified that the program shouldn't accept lengths greater than 30? If not, you should probably allow much greater lengths. > function Sum_Of_Divisors ( [...] > for I in 1 .. N - 1 loop Numbers greater than half of N can't very well be divisors of N. You could cut the execution time in half by looping over 1 .. N / 2 instead. > procedure Sociable_Chain ( > Minnumber, > Maxnumber : Natural ) is You need to think more about the parameters to this procedure. What do you need to know to start calculating a chain? > A : array (1 .. 30) of Positive; > I : Positive; You could let the upper bound of A be the maximum length that the user entered instead of a fixed number. Then only the computer's memory would limit how long chains you could handle. A and I should have more descriptive names. > > begin > A(1) :=Minnumber; Here Minnumber seems to be a starting point rather than a minimum. > A(2) := Sum_Of_Divisors (A(1)); > while I < Length and A (1) /= A(I) loop What value will I have the first time you reach this point? > I:= I + 1; > A(I) := Sum_Of_Divisors (A(I - 1)); > > > end loop; Now you need to find out whether the loop ended because a sociable chain was found or because the maximum length was exceeded � and if a chain was found you know what to do with it, don't you? > > end Sociable_Chain; -- Bj�rn Persson PGP key A88682FD omb jor ers @sv ge. r o.b n.p son eri nu