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=0.1 required=5.0 tests=BAYES_40,FREEMAIL_FROM, PLING_QUERY autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,7d1a02b763945274,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.224.72.199 with SMTP id n7mr56607451qaj.5.1358286764889; Tue, 15 Jan 2013 13:52:44 -0800 (PST) Received: by 10.182.162.41 with SMTP id xx9mr1878449obb.4.1358286764772; Tue, 15 Jan 2013 13:52:44 -0800 (PST) Path: k2ni11qap.0!nntp.google.com!p13no344592qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 15 Jan 2013 13:52:44 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=134.240.12.204; posting-account=CZZpzgoAAAAoaHoNNp9zhY9EzQgEmxhU NNTP-Posting-Host: 134.240.12.204 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Algorithms Homework Help?!?! From: willmann817 Injection-Date: Tue, 15 Jan 2013 21:52:44 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2013-01-15T13:52:44-08:00 List-Id: I am given an Array that contains the number of M&Ms of each color I have. Each index in the array represents a different color. I am also given an Integer of the number of children I am having at a birthday party. --THE CHILDREN MUST ALL HAVE THE SAME NUMBER OF M&MS --EACH CHILD MUST ONLY HAVE 1 COLOR OF M&MS Given an array containing the number of M&Ms I have in each available color, and the number of kids, determine the maximum number of M&Ms you can put in each goody bag. For example, with 11 red M&Ms, 9 blue M&Ms, and 5 M&Ms, you could give 5 children a maximum of 4 M&Ms each. You could not give each child 5 M&Ms without at least one child receiving M&Ms of different colors. I was given a hint that said to write a helper function Groups(M : Integer; A : Int_Array) that takes a number of M&Ms and the array and returns how many groups I can make of M pieces of M&Ms. (For example, with 11 red bricks, 9 blue bricks, and 5 green bricks, Groups(3) would return 7.) Then do my binary search based on this helper function(Posted below). --This problem MUST include Binary Search in some way. I completed that but now I am stuck on the main function(also posted below) it is totally wrong cause I can't even pass the first test case: function Groups(Bricks : Integer; A: Int_Array) return Integer is counter : Integer := 0; begin for I in A'Range loop counter := counter + (A(I)/Bricks); end loop; return counter; function Candy(Kids : Integer; MsPerColor : Int_Array) return Integer is lo : Integer := 1; hi : Integer := 50000; mid : Integer; begin for I in MsPerColor'Range loop if MsPerColor(I) > hi then hi := MsPerColor(I); end if; if MsPerColor(I) < lo then lo := MsPerColor(I); end if; end loop; mid := (lo+hi)/2; while Groups(mid, MsPerColor) /= Kids loop mid := (lo+hi)/2; if Groups(mid, MsPerColor) > Kids then hi := mid; else lo := mid; end if; end loop; return mid; end Candy; end Groups;