From: Simon Wright <simon@pushface.org>
Subject: Re: Marble Clock
Date: Sat, 13 Apr 2013 06:51:21 +0100
Date: 2013-04-13T06:51:21+01:00 [thread overview]
Message-ID: <lyd2tzf06e.fsf@pushface.org> (raw)
In-Reply-To: e3763890-38c3-4fe2-a776-726e77f53528@googlegroups.com
gattamaneni abhiram <abhiram.gattamaneni@gmail.com> 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;
next prev parent reply other threads:[~2013-04-13 5:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-02 0:09 Marble Clock gattamaneni abhiram
2013-04-02 12:02 ` John B. Matthews
2013-04-02 19:46 ` gattamaneni abhiram
2013-04-02 19:54 ` Eryndlia Mavourneen
2013-04-03 9:14 ` Simon Wright
2013-04-03 12:45 ` Eryndlia Mavourneen
2013-04-03 16:53 ` Simon Wright
2013-04-12 22:28 ` gattamaneni abhiram
2013-04-13 5:51 ` Simon Wright [this message]
2013-04-13 19:04 ` Dennis Lee Bieber
2013-04-03 11:52 ` John B. Matthews
2013-04-03 7:44 ` Mike H
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox