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.8 required=5.0 tests=BAYES_00,FREEMAIL_FROM, PLING_QUERY autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,7d1a02b763945274 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.224.192.199 with SMTP id dr7mr18233721qab.4.1358293399885; Tue, 15 Jan 2013 15:43:19 -0800 (PST) Received: by 10.49.63.164 with SMTP id h4mr16303340qes.39.1358293399867; Tue, 15 Jan 2013 15:43:19 -0800 (PST) Path: k2ni11qap.0!nntp.google.com!p13no412547qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 15 Jan 2013 15:43:19 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.153.59.64; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 69.153.59.64 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <8a4f61cd-9d6e-4bc5-b28c-c14e1ac2e096@googlegroups.com> Subject: Re: Algorithms Homework Help?!?! From: Shark8 Injection-Date: Tue, 15 Jan 2013 23:43:19 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2013-01-15T15:43:19-08:00 List-Id: Um, there's nothing there suggestive of a binary-search, or ANY search. But here's an example of how to do the groupings. Pragma Ada_2012; With Ada.Text_IO, Ada.Text_IO.Text_Streams; Procedure Test is Type Color is ( Red, Blue, Green, Yellow, Brown ); Type MM_Array is Array(Color Range <>) of Natural; -------------------------- -- Forward Declarations -- -------------------------- Function Maximum( Candy : MM_Array ) Return Natural with Pre => Candy'Length in Positive; Function Group( Group_Size : Positive; Candy : MM_Array ) Return Natural with Pre => Candy'Length in Positive AND Maximum(Candy) >= Group_Size; ----------------------- -- Function Bodies -- ----------------------- Function Maximum( Candy : MM_Array ) Return Natural is begin Return Result : Natural := Natural'First do For Value of Candy loop Result:= Natural'Max( Result, Value ); End loop; End return; end Maximum; Function Group( Group_Size : Positive; Candy : MM_Array ) Return Natural is begin Return Result : Natural := 0 do For Value of Candy loop Result:= Result + Value / Group_Size; End loop; End return; end Group; Candies : MM_Array := (Red => 11, Blue => 9, Green => 5); Begin Ada.Text_IO.New_Line; Ada.Text_IO.Put_Line( "Max: " & Maximum(Candies)'Img ); Ada.Text_IO.Put_Line( "Group:" & Group(8, Candies)'Img ); End Test;