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!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 07 May 2016 12:43:47 -0500 From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: Help with tasks Date: Sat, 07 May 2016 13:43:52 -0400 Organization: IISS Elusive Unicorn Message-ID: References: <410b222c-9443-46b7-8a18-2fc3d05772a9@googlegroups.com> X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 108.73.119.24 X-Trace: sv3-SzcveH0V/cZhzs/aVCWdcbe2qyOeqAmsaloAXaFjhCvqMUAIvXcX9zDoO/HKktTlYQv2fIL5Dx8xm50!GmLpq2BqVCHM8iZ2X+X2eCLap2QXNYsEEMNDVMWHoiknbjLfXYL4JxkpQ9WbfXAd4O+uB8xkFM1T!4ITwMnTdaZgecpTsgAocSvGYmQE= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4434 X-Received-Bytes: 4546 X-Received-Body-CRC: 2572904017 Xref: news.eternal-september.org comp.lang.ada:30350 Date: 2016-05-07T13:43:52-04:00 List-Id: On Sat, 7 May 2016 07:53:28 -0700 (PDT), danifreecs@gmail.com declaimed the following: > >The project: There's a garden with 10 plots, and a locust gets in 1 of the plots, so the gardener wants to kill it with poison. The locust randomly changes plots in a time, and the gardener can spray 1 plot/day (either randomly), which gets clean from poison after that day has passed. The locust dies if it jumps into the sprayed plot, or is in it already. The simulation goes until the locust dies. For the random number generation and the console output use a common protected object. (Monitor) > Well, strictly speaking -- protected objects are not to perform blocking operations; console output is a potentially blocking operation. Now -- using the protected object to hold the state of the plots, with a separate display task (could be the main program) using a locking access to retrieve the entire state at once for output/display might work... Question: "locust randomly changes plots in a time" is unclear. The gardener is a one per simulated day, but what is the simulation time frame for the locust? Also one move per day? Is that the actual text of the assignment, or did you paraphrase it? If both are one move per day, the whole idea of using tasks and protected objects becomes moot. Since the poison clears out after a day, one can assume every day starts with a clean slate. The only way to end is for the gardener and the locust to move to the same plot (doesn't matter who moves first since they effectively stay there until the next day). That is: loop gardener: = random(10) locust := random(10) display "gardener is in plot" gardener display "locust is in plot" locust exit if gardener = locust display "locust survived the day" display " " end loop display "locust is dead" If the locust can move multiple times in a day, then you need some sort of simulation clock (say the locust moves every 6 hours -- the simulation clock would be modulo 4 [0, 1, 2, 3, 0 ...], and the gardener moves only on [0] which would also be when the plot(s) clear of the previous poison) Still doesn't really need tasks... clock := 0 loop if clock = 0 then gardener = random(10) end if locust := random(10) -- since the only poisoned plot is the one the gardener is in display "gardener is in plot" gardener display "locust is in plot" locust exit if gardener = locust display "locust survived the move" display " " end loop display "locust is dead" Now, if the poison actually lasts the day of the spraying AND the next day... Then you need some structure to represent the 10 plots and if they are poisoned (a value in the range of 0..2 would suffice; when a plot is sprayed, that entry is set to 2; on each day [still need a simulation clock] non-zero entries are decremented by 1. If the locust enters a plot with a non-zero entry, it dies. As for a working example? Sorry -- most of the ethical folks won't do one's homework for them. Show us what you've written, tell us what you expected it to do, and what it really is doing, and we'll tender explanations of what may be in error. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/