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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Marble Clock Date: Sat, 13 Apr 2013 06:51:21 +0100 Organization: A noiseless patient Spider Message-ID: References: <7075541f-01b7-4cd4-997f-b0b8048f067d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="759faf2487b2ffad9ca6f5463a606de4"; logging-data="20400"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//j5sstkxeHnzFl21tzBSIoOKBiOGi5Y0=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (darwin) Cancel-Lock: sha1:v5JmuOtWBiLqsn/VgFYtfumxz6Q= sha1:dPZNmatvcONnzxPrf7YwCAGA1S4= Xref: news.eternal-september.org comp.lang.ada:14984 Date: 2013-04-13T06:51:21+01:00 List-Id: gattamaneni abhiram writes: > Thank You for the help. I completed the coding part using stacks for > the trays and a Queue for the reservoir. Good to hear it! > I am stuck at a point, I need > to determine the number of 12-hour cycles the clock goes through > before the marbles in the reservoir are back in their original order > (relative to the number of input marbles used to fill the > reservoir). Can you help me with this? You could give each marble a position number with something like type Marble (Position : Positive) is null record; and check at the end of each cycle whether the marbles are now in order. Are you using Ada.Containers.*Synchronized_Queues? If not, you'll probably be able to get access to the queue contents to do this check; but if you are, you'd need to pop the items, check they're in order, and requeue. In_Order : Boolean := True; begin for J in 1 .. Reservoir.Current_Use loop declare M : Marble; begin Reservoir.Dequeue (M); Reservoir.Enqueue (M); if M.Position /= J then In_Order := False; end if; end; end loop; If you do this, you'll need to redefine Marble above to allow M.Position to be changed: either supply a default type Marble (Position : Positive := 1) is null record; or make it a component type Marble is record Position : Positive; end record;