Due: 2018-Oct-16 23:5915 15:00, D2L and hardcopy 10% extra-credit if submitted before break, by Oct.14 23:59.
Updates:ignoring formatting and minor phrasing changes
Oct.15 10:03:
Note that Dr Okie's assignment's sample-run output
mentions certain situtations
not addressed by the one sample on this page.
You may use either his “preferred” or “allowed” output, in those situations.
Oct.14 20:20: The online checker has been corrected.
Oct.14 17:50: [update: fixed 20:20]
Note that the online checker is currently showing each line's “traveling ...” correctly,
but the total-distance for tethered omits the last travel (using 1 instead).
It will be fixed momentarily; in the mean time your output should match each individual aisle/line,
and you can check by hand that your total is correct.
Oct.13 08:30: Change output format for last aisle: before “crossing”, stop in that aisle then continue to other side.
Full credit for previous format will also be accepted.
Oct.13 08:30: Not a change:
Note that Dr. Okie’s on-line checker is slightly different from our requirement: one of the summary lines is labeled “Aisle average:”
instead of “Average:”.
Oct.08 17:05: Fixed “tethered” output: aisle 8 not in the near-half, and later continuing (not reversing) to the cashier.
Oct.08 17:05: Clarified that there will be guaranteed at least one item in some aisle's near-half, and also in some aisle's far-half.
Oct.02 21:15: Clarified (including footnotes), and improved formatting.
Last modified
You can see a running example of this program at Dr. Okie’s nifty assignment checker
(which uses gnoga to
integrate the GUI, web server, and problem solution).
On-campus or VPN session required.
This programming assignment is similar to shop.html,
but there are several important differences:
In the input, the aisles and locations are no longer sorted.
Aisle-location pairs can now come in any order.
Reading continues until end of file (i.e. end of standard input). There is no sentinel pair at the end of the input
You are to use a two-dimensional array of booleans to represent
whether or not each aisle location is to be visited. (Or an array of arrays of booleans).
You are to implement two strategies for visiting those locations,
a “tethered” and an “untethered” strategy:
Tethered.
This is a new strategy: go down the near end of the aisles and visit all of the locations
that are in the near half, then go down the far end of the aisles and visit all of the locations that are
on the far half. For the near half, start at the first aisle,
and for the far half, return to the first aisle.
You can think of being tethered to the end of each aisle1.
Untethered.
The second approach is the same as in the previous assignment:
after visiting all of the locations in an aisle,
use the specified locations in the next aisle to decide whether it's shorter to continue or reverse to visit the next aisle.
You must design a solution that uses helper procedures and functions
wherever it makes good sense to do so. Each of these helper routines should
have a single, clearly defined purpose.
Sample Run:
Here is a sample run of the program.
Assume that this sample input data is in the file in7.txt:
3 14 8 98 3 16 3 15
2 3 2 1 2 2
5 97 5 98 5 99
7 1 7 2 7 8 7 9
8 97 8 99
9 95
9 96 9 97
11 2
Assume that you run the program from the command line,
with the input redirected from this input file, as follows:
rucs% tethered < in7.txt
Then this will be the resulting output:
Tethered:
Continue and enter aisle 2 at 0 and proceed to location 3, traveling 3
Reverse and enter aisle 3 at 0 and proceed to location 16, traveling 19
Reverse and enter aisle 7 at 0 and proceed to location 9, traveling 25
Reverse and enter aisle 11 at 0 and proceed to location 2, traveling 11
Continue and enter aisle 9 at 100 and proceed to location 95, traveling 103
Reverse and enter aisle 8 at 100 and proceed to location 97, traveling 8
Reverse and enter aisle 5 at 100 and proceed to location 97, traveling 6
Continue and exit aisle 5 at 0 and proceed to cashier, traveling 97
Aisle count: 7
Total distance: 272
Average: 38.9
Untethered:
Continue and enter aisle 2 at 0 and proceed to location 3, traveling 3
Reverse and enter aisle 3 at 0 and proceed to location 16, traveling 19
Continue and enter aisle 5 at 100 and proceed to location 97, traveling 87
Reverse and enter aisle 7 at 100 and proceed to location 1, traveling 102
Continue and enter aisle 8 at 0 and proceed to location 99, traveling 100
Continue and enter aisle 9 at 100 and proceed to location 95, traveling 6
Continue and enter aisle 11 at 0 and proceed to location 2, traveling 97
Reverse and exit aisle 11 at 0 and proceed to cashier, traveling 2
Aisle count: 7
Total distance: 416
Average: 59.4
Notes:
Note that if aisle 11 were not in the input, then aisle 9 would have been traversed from 0 to 100.
Do not use global variables!
As in the previous assignment,
the last line in each group is different from the others,
even though bits of it should align with the previous lines.
It will always contain “exit” and “at 0” and “cashier, ”.
Input specification:
Input is a sequence pairs of natural numbers, each of which represents an aisle and location.
Aisle numbers can be in any order, and within an aisle, location numbers can be in any order.
Reading continues until end_of_file.
Notice, there is no terminating 0 0 in the input.
Except for the final number, there can be arbitrary white space surrounding each number.
The final number will be followed only by a newline, then the end-of-file.2
Aisle numbers to process will be between 1 and 1_000, inclusive.
Location numbers will be between 0 to 100, inclusive.
There will always be at least one item in the near-half of some aisle, and at least one item in the far-half of some aisle to process.
For some extra-credit:
Have your code work even without the in-each-half guarantee
(and perhaps even without needing any items at all!).
(Mention this feature in your comments, so we'll know to look for that.)
Your program does not need to check for errors in the input.
Your program is to read from stdin (which is the default for Ada.Text_IO.Get).
Output specification: Essentially the same as the previous assignment.
Introduce each group with either the word "Tethered" or "Untethered".
For each aisle you are to display the sentence shown in the example, with the following:
Either the word "Reverse" or "Continue", to indicate whether or not you changed direction
The aisle number
The aisle entry location
The last location visited in the aisle.
The distance walked to get that position from the previous position
After processing all of the aisles (for each the tethered and untethered algorithms),
your program should print a summary:
The number of aisles visited.
The total distance traveled.
The average distance traveled per aisle.
Your output should follow the format of the example precisely, including blanks and columns:
Numeric field of width 5 for the aisle.
Numeric fields of width 4 for locations and distance.
Exactly one blank between colons and the aisle count, total distance, and average.
Average printed with one decimal place.
A blank line (i.e. containing only a line separator) between the aisle information and the summary.
A blank line (i.e. containing only a line separator) before “Untethered”.
It follows from this, that: your program is to have no prompts.
Distance:
Aisles are of course numbered starting from one. Within an aisle, we'll number locations from 0 to a maximum amount (for this assignment, 100). You might think of location 0 being the end of the aisle near the front of the store, and the maximum-location-number as being at the back of the store.
Locations do not have any width;
for example, within an aisle, location 20 is distance 20 from location 0, and is distance 80 from location 100. Locations 0 and 100 are themselves valid locations (You might think of them as endcaps).
You can assume that you begin walking at aisle 1, location 0.
Only consider the distance that you walk up an down the aisles.
Do not include the distance walked from one aisle to the next.
As in the previous assignment, after processing the locations in an aisle, if going either direction results in the same distance,
then you should continue in the direction that you are going (i.e. continuing going forward, instead of
reversing).
This of course applies only to the non-tethered version.
Extra credit:
Specify verbose vs quiet execution with a command line argument. Here are some example executions:
Quiet mode is to print only the 3 line summary for each method.
Verbose mode is to print the output specified in the assignment (i.e.verbose is the default3.
Invalid flags should be reported with warnings.
Here and here are examples of using the command line.
If more than one flag are given, your program can do anything (including crash),
but please mention the behavior in a comment, as well as what more-desired behavior you
might implement had you more time.
Other points
You must use a 2D array of booleans (or an array of arrays of booleans).
You must break decompose your program into procedures and functions.
You must define appropriate types or subtypes for aisle-numbers and locations.
You must define a type to represent which end of the aisle you use, rather than 0 or 100. (I called the two values of that type near and far.)
Use named constants as appropriate.
Use good variable-names ("self-documenting").
Do not store the locations in a collection of any kind (e.g. no arrays and no lists).
Read numbers using numeric I/O, not by reading the input as one or more strings.
Make sure that your program reads from stdin, not from a file whose name is specified in the program.
Your program should be called tethered.adb
See the previous assignment for information on creating data files,
standard input, (stdin)
redirection, end of file for intereactive input, and good style.
One of the difficulties of the tethered algorithm is changing from processing the near-ends (Location 0) to processing the
far-ends (Location 100) of the aisles.
There are two simplistic ways of doing this that simplify the problem a little. You might want to try one of them first.
Always go to the very-last aisle and walk all the way down it to get to the other end of the aisles
(i.e. to start processing the far ends of the aisles).
Treat the last aisle processed before turning around the same as any other, and then turn around.
In other words, if aisle 11 had locations 2 and 99, go from 0 to 2, reverse back to 0,
then move to 100,
then to 99 and reverse to 100 (whew -- definitely not optimal!).
1 Maybe the shopper is a Roomba, and its power-cord only reaches halfway down an aisle.
Or, maybe the store's wireless has a dead spot at the middle of each aisle,
keeping the reddit-reading-shopper from wanting to cross that zone.
↩
2 This is so that immediately after reading that last number,
end_of_file will return True.
↩
3 Traditional Unix programs are quiet by default, and verbose only with a flag.
However, we have backwards compatibility with the non-extra-credit version to consider.
↩