comp.lang.ada
 help / color / mirror / Atom feed
* Marble Clock
@ 2013-04-02  0:09 gattamaneni abhiram
  2013-04-02 12:02 ` John B. Matthews
  2013-04-03  7:44 ` Mike H
  0 siblings, 2 replies; 12+ messages in thread
From: gattamaneni abhiram @ 2013-04-02  0:09 UTC (permalink / raw)


A marble clock is a clock that indicates the current time in a 24-hour day using
marbles to represent portions of the hour and day. There are many different kinds of marble clocks, distinguished by variations in the way the marbles represent portions of the day. Our marble clock consists of five shallow "trays" arranged one above the other. The bottom tray (the fifth tray) serves as a marble "reservoir." Every minute, a winding mechanism picks up one marble from the bottom tray, carries it to the top of the clock and drops it into the top tray of the clock. As a tray fills up, marbles fall through to lower level trays, as described below. The current state of the marbles in the upper four trays tells the current time.

Each marble in the top tray (first tray) represents a single minute. This first tray has room for four marbles. These marbles all enter from the same end and roll down to the other end of the tray. When the first tray is full, the next marble drops to the second tray (the second tray represents 5 minute intervals) and, in the process, trips a latch that tilts the top tray causing the marbles there to exit the same end that they entered and return to the end of the line in the reservoir (bottom) tray. The second tray holds a maximum of two marbles, and when a third marble arrives, it drops to the next tray (representing 15 minute intervals). Then, the second tray is emptied in a manner analogous to the first. Finally, the third (15-minute) tray can hold three marbles and a fourth marble drops into the hours tray (fourth tray), causing the 15 minute tray to be emptied back into the reservoir. The hours tray holds 11 marbles, when a twelfth marble arrives, it trips the tray which empties into the reservoir. The tripping marble then also drops into the reservoir, completing the cycle. Thus, a complete cycle is 12 hours.

Above behaviour of the clock is to be implemented using stacks and queues.
The initial number of marbles to be taken is the user input.

Can anyone please help me with the logic in the program?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  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-03  7:44 ` Mike H
  1 sibling, 1 reply; 12+ messages in thread
From: John B. Matthews @ 2013-04-02 12:02 UTC (permalink / raw)


In article <7075541f-01b7-4cd4-997f-b0b8048f067d@googlegroups.com>,
 gattamaneni abhiram <abhiram.gattamaneni@gmail.com> wrote:

> A marble clock is a clock that indicates the current time in a 
> 24-hour day using marbles to represent portions of the hour and 
> day. There are many different kinds of marble clocks, 
> distinguished by variations in the way the marbles represent 
> portions of the day. Our marble clock consists of five shallow 
> "trays" arranged one above the other. The bottom tray (the fifth 
> tray) serves as a marble "reservoir." Every minute, a winding 
> mechanism picks up one marble from the bottom tray, carries it to 
> the top of the clock and drops it into the top tray of the clock. 
> As a tray fills up, marbles fall through to lower level trays, as 
> described below. The current state of the marbles in the upper 
> four trays tells the current time.

For reference, an elapsed-time video of a three-tier version is 
seen here:

<http://www.scientificsonline.com/time-machine-ball-bearing-click.html>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  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 11:52     ` John B. Matthews
  0 siblings, 2 replies; 12+ messages in thread
From: gattamaneni abhiram @ 2013-04-02 19:46 UTC (permalink / raw)


On Tuesday, 2 April 2013 08:02:45 UTC-4, John B. Matthews  wrote:
> In article <7075541f-01b7-4cd4-997f-b0b8048f067d@googlegroups.com>,
> 
>  gattamaneni abhiram <abhiram.gattamaneni@gmail.com> wrote:
> 
> 
> 
> > A marble clock is a clock that indicates the current time in a 
> 
> > 24-hour day using marbles to represent portions of the hour and 
> 
> > day. There are many different kinds of marble clocks, 
> 
> > distinguished by variations in the way the marbles represent 
> 
> > portions of the day. Our marble clock consists of five shallow 
> 
> > "trays" arranged one above the other. The bottom tray (the fifth 
> 
> > tray) serves as a marble "reservoir." Every minute, a winding 
> 
> > mechanism picks up one marble from the bottom tray, carries it to 
> 
> > the top of the clock and drops it into the top tray of the clock. 
> 
> > As a tray fills up, marbles fall through to lower level trays, as 
> 
> > described below. The current state of the marbles in the upper 
> 
> > four trays tells the current time.
> 
> 
> 
> For reference, an elapsed-time video of a three-tier version is 
> 
> seen here:
> 
> 
> 
> <http://www.scientificsonline.com/time-machine-ball-bearing-click.html>
> 
> 
> 
> -- 
> 
> John B. Matthews
> 
> trashgod at gmail dot com
> 
> <http://sites.google.com/site/drjohnbmatthews>

Do I need to use timer functions in the program to depict the changes in the places of the marbles in different trays?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  2013-04-02 19:46   ` gattamaneni abhiram
@ 2013-04-02 19:54     ` Eryndlia Mavourneen
  2013-04-03  9:14       ` Simon Wright
  2013-04-03 11:52     ` John B. Matthews
  1 sibling, 1 reply; 12+ messages in thread
From: Eryndlia Mavourneen @ 2013-04-02 19:54 UTC (permalink / raw)


On Tuesday, April 2, 2013 2:46:10 PM UTC-5, gattamaneni abhiram wrote:
> On Tuesday, 2 April 2013 08:02:45 UTC-4, John B. Matthews  wrote:
> 
> > In article <7075541f-01b7-4cd4-997f-b0b8048f067d@googlegroups.com>,
> 
> > 
> 
> >  gattamaneni abhiram <abhiram.gattamaneni@gmail.com> wrote:
> 
> > 
> 
> > 
> 
> > 
> 
> > > A marble clock is a clock that indicates the current time in a 
> 
> > 
> 
> > > 24-hour day using marbles to represent portions of the hour and 
> 
> > 
> 
> > > day. There are many different kinds of marble clocks, 
> 
> > 
> 
> > > distinguished by variations in the way the marbles represent 
> 
> > 
> 
> > > portions of the day. Our marble clock consists of five shallow 
> 
> > 
> 
> > > "trays" arranged one above the other. The bottom tray (the fifth 
> 
> > 
> 
> > > tray) serves as a marble "reservoir." Every minute, a winding 
> 
> > 
> 
> > > mechanism picks up one marble from the bottom tray, carries it to 
> 
> > 
> 
> > > the top of the clock and drops it into the top tray of the clock. 
> 
> > 
> 
> > > As a tray fills up, marbles fall through to lower level trays, as 
> 
> > 
> 
> > > described below. The current state of the marbles in the upper 
> 
> > 
> 
> > > four trays tells the current time.
> 
> > 
> 
> > 
> 
> > 
> 
> > For reference, an elapsed-time video of a three-tier version is 
> 
> > 
> 
> > seen here:
> 
> > 
> 
> > 
> 
> > 
> 
> > <http://www.scientificsonline.com/time-machine-ball-bearing-click.html>
> 
> > 
> 
> > 
> 
> > 
> 
> > -- 
> 
> > 
> 
> > John B. Matthews
> 
> > 
> 
> > trashgod at gmail dot com
> 
> > 
> 
> > <http://sites.google.com/site/drjohnbmatthews>
> 
> 
> 
> Do I need to use timer functions in the program to depict the changes in the places of the marbles in different trays?

I believe that would be the simpler way to do it.  Of course, you always can simulate the materials and workmanship of an actual clock with masses, gravitational acceleration, etc.  :-)

Note that the non-realtime timer in Ada is the "delay" statement:  "delay 3.1", for example, will delay for 3.1 seconds.

-- Eryndlia



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  2013-04-02  0:09 Marble Clock gattamaneni abhiram
  2013-04-02 12:02 ` John B. Matthews
@ 2013-04-03  7:44 ` Mike H
  1 sibling, 0 replies; 12+ messages in thread
From: Mike H @ 2013-04-03  7:44 UTC (permalink / raw)


In message <7075541f-01b7-4cd4-997f-b0b8048f067d@googlegroups.com>, 
gattamaneni abhiram <abhiram.gattamaneni@gmail.com> writes
>Can anyone please help me with the logic in the program?

Stand back and list what properties do the trays share with each other 
and in what ways they differ. Then look at those lists of properties as 
abstractions and try to decide whether each, in turn, has any of the 
characteristics of a stack, of a queue or of neither.

If you spot sufficient shared properties, you might even gather some 
extra brownie points with your assessor by considering whether to use 
generic objects.
-- 
Time flies like an arrow. Fruit flies like a banana.
Mike



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  2013-04-02 19:54     ` Eryndlia Mavourneen
@ 2013-04-03  9:14       ` Simon Wright
  2013-04-03 12:45         ` Eryndlia Mavourneen
                           ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Simon Wright @ 2013-04-03  9:14 UTC (permalink / raw)


Eryndlia Mavourneen <eryndlia@gmail.com> writes:

> On Tuesday, April 2, 2013 2:46:10 PM UTC-5, gattamaneni abhiram wrote:

>> Do I need to use timer functions in the program to depict the changes
>> in the places of the marbles in different trays?
>
> I believe that would be the simpler way to do it.  Of course, you
> always can simulate the materials and workmanship of an actual clock
> with masses, gravitational acceleration, etc.  :-)
>
> Note that the non-realtime timer in Ada is the "delay" statement:
> "delay 3.1", for example, will delay for 3.1 seconds.

You (gattameini) definitely should *not* use more than one timer
function (when_to_run := when_to_run + 1.0; delay until when_to_run;),
for when the next marble is to enter the top tray.

IRL there will be a finite delay for the mechanism to click through any
carries that may be needed, but I very much doubt you're required to
simulate that.


BTW, people, did you notice how I trimmed the quoted part of this so
that it only contains the bit I'm actually replying to? You seem to be
Google Groups users, so you probably don't notice what a complete pig's
ear GG makes of quoting!!!



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  2013-04-02 19:46   ` gattamaneni abhiram
  2013-04-02 19:54     ` Eryndlia Mavourneen
@ 2013-04-03 11:52     ` John B. Matthews
  1 sibling, 0 replies; 12+ messages in thread
From: John B. Matthews @ 2013-04-03 11:52 UTC (permalink / raw)


In article <e20eda83-2320-48ca-83da-b13d7df3dc1c@googlegroups.com>,
 gattamaneni abhiram <abhiram.gattamaneni@gmail.com> wrote:

> Do I need to use timer functions in the program to depict the changes 
> in the places of the marbles in different trays?

You're modeling a clock that works by stacking balls on a level 
representing one time unit until that unit overflows, incrementing the 
next higher time unit. A series of LIFO stacks might be a good choice. 
The delay timer suggested by Eryndlia would drive your model at whatever 
rate you choose: shorter delay -> faster simulation.

Initially, your choice "to depict the changes" should be simple, perhaps 
using Ada.Text_IO.

See also:

<http://www.patriciashanahan.com/beginner.html>
<http://rosettacode.org/wiki/Stack#Ada>

-- 
[Please do not quote signatures.]



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  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
  2 siblings, 0 replies; 12+ messages in thread
From: Eryndlia Mavourneen @ 2013-04-03 12:45 UTC (permalink / raw)


On Wednesday, April 3, 2013 4:14:07 AM UTC-5, Simon Wright wrote:
>> Eryndlia Mavourneen <eryn...@gmail.com> writes:
> BTW, people, did you notice how I trimmed the quoted part of this so
> 
> that it only contains the bit I'm actually replying to? You seem to be
> 
> Google Groups users, so you probably don't notice what a complete pig's
> 
> ear GG makes of quoting!!!

Whoops -- LOL  End-of-workday post.  And yes, perhaps if enough of us complain to GG, *maybe* they will make it better.

-- Eryndlia



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  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
  2 siblings, 0 replies; 12+ messages in thread
From: Simon Wright @ 2013-04-03 16:53 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> You (gattameini) definitely should *not* use more than one timer
> function (when_to_run := when_to_run + 1.0; delay until when_to_run;),
> for when the next marble is to enter the top tray.

Sorry, I've just re-read the question: that should be 60.0 seconds, not
1.0!

The point I was trying & probably failing to make is that 'delay 60.0'
results in a delay of _at least_ 60 seconds, which would make your clock
run slow. This is rather an advanced point, probably not relevant to
your exercise.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  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
  2013-04-13 19:04           ` Dennis Lee Bieber
  2 siblings, 2 replies; 12+ messages in thread
From: gattamaneni abhiram @ 2013-04-12 22:28 UTC (permalink / raw)


On Wednesday, April 3, 2013 5:14:07 AM UTC-4, Simon Wright wrote:
> Eryndlia Mavourneen <eryndlia@gmail.com> writes:
> 
> 
> 
> > On Tuesday, April 2, 2013 2:46:10 PM UTC-5, gattamaneni abhiram wrote:
> 
> 
> 
> >> Do I need to use timer functions in the program to depict the changes
> 
> >> in the places of the marbles in different trays?
> 
> >
> 
> > I believe that would be the simpler way to do it.  Of course, you
> 
> > always can simulate the materials and workmanship of an actual clock
> 
> > with masses, gravitational acceleration, etc.  :-)
> 
> >
> 
> > Note that the non-realtime timer in Ada is the "delay" statement:
> 
> > "delay 3.1", for example, will delay for 3.1 seconds.
> 
> 
> 
> You (gattameini) definitely should *not* use more than one timer
> 
> function (when_to_run := when_to_run + 1.0; delay until when_to_run;),
> 
> for when the next marble is to enter the top tray.
> 
> 
> 
> IRL there will be a finite delay for the mechanism to click through any
> 
> carries that may be needed, but I very much doubt you're required to
> 
> simulate that.
> 
> 
> 
> 
> 
> BTW, people, did you notice how I trimmed the quoted part of this so
> 
> that it only contains the bit I'm actually replying to? You seem to be
> 
> Google Groups users, so you probably don't notice what a complete pig's
> 
> ear GG makes of quoting!!!

Thank You for the help. I completed the coding part using stacks for the trays and a Queue for the reservoir. 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?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  2013-04-12 22:28         ` gattamaneni abhiram
@ 2013-04-13  5:51           ` Simon Wright
  2013-04-13 19:04           ` Dennis Lee Bieber
  1 sibling, 0 replies; 12+ messages in thread
From: Simon Wright @ 2013-04-13  5:51 UTC (permalink / raw)


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;

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Marble Clock
  2013-04-12 22:28         ` gattamaneni abhiram
  2013-04-13  5:51           ` Simon Wright
@ 2013-04-13 19:04           ` Dennis Lee Bieber
  1 sibling, 0 replies; 12+ messages in thread
From: Dennis Lee Bieber @ 2013-04-13 19:04 UTC (permalink / raw)


On Fri, 12 Apr 2013 15:28:42 -0700 (PDT), gattamaneni abhiram
<abhiram.gattamaneni@gmail.com> declaimed the following in
comp.lang.ada:

> Thank You for the help. I completed the coding part using stacks for the trays and a Queue for the reservoir. 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?

	That sounds more like an exercise in permutation and
combinatorial...

	What really confuses the matter is, based on your original
description, the marbles being returned to the reservoir when a tray is
emptied will be in /reverse order/ for the tray (you state that a tray
empties from the same end it is filled).

	The inefficient method would be to number the marbles, remove any
"real time" delay, run a 12-hour cycle as fast as the machine can
process, check the reservoir marble order, and repeat keeping track of
the cycles, until the marbles are in order...

	The efficient method would be to derive some formula for how the
marbles get permuted. Maybe determine the minimum number of marbles that
can operate a 12-hour cycle and determine how many cycles are needed for
that to return to original. Add one marble and see how many cycles that
takes. Add a second marble and count cycles. Then see if there is some
easy math to handle larger number counts. Is there a progression: did 1
marble over minimum require 720 times the minimum clock marbles (720
minutes in 12 hours), did 2 marbles over take 720 times the 1 marble
over... That would indicate that raising 720 to (reservoir - minimum)
would give the multiplier to the number of cycles used by the minimum
count -- you might need to test for a few larger counts to confirm the
hypothesis...

11 hours, 3 15min, 2 5min, 4 min, and 1 to cascade the whole mess -- 21
marbles is the minimum?

abcdefghijklmnopqrstu

bcdefghijklmnopqrstu		a		<>		<>		<>
cdefghijklmnopqrstu		ab		<>		<>		<>
defghijklmnopqrstu		abc		<>		<>		<>
efghijklmnopqrstu			abcd	<>		<>		<>
fghijklmnopqrstudcba		<>		e		<>		<>
...
jklmnopqrstudcba			fghi		e		<>		<>
klmnopqrstudcbaihgf		<>		ej		<>		<>


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-04-13 19:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2013-04-13 19:04           ` Dennis Lee Bieber
2013-04-03 11:52     ` John B. Matthews
2013-04-03  7:44 ` Mike H

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox