<Task>
Desk top icons are those you see on the PC screen. If they are scattered on the screen, just click the "Sort by" menu and they will be arranged in the form of rectangle or one with a line of icons attached on the right side. The arrangements in the right is a rectangle of H=6 by W=7 with a line of A=4. Suppose that you move a mouse so that the mouse poiner hovers over the icons through the corners but not through the sides. At the sides of the rectangle where no icon exists beyond the corner, the mouse pointer is reflected. At the corners, whether they are protruding or receding, the movement is terminated. The figure at right shows an example of the trajectory. In a sense the mouse pointer were moved as if it were carried by light. Now the task is to make a computer program that will predict the trajectory for any parameter set of (H, W, A). In practice the parameter values may be at most 30. The trajectory length may be finite or infinite depending on the start position. |
<Traversing over desktop icons >
Each icon is referred to as ID, which ranges from 0 (upper-left corner) to Length-1 (lower-right corner). |
Structure of the Program | |
<Python>
Run in the VS Code/Anaconda environment. The (main) program is named DeskTopIcons.py. The following modules are also made.
The code development was relatively alleviated because Modula-2 code was completed first, but two-dimensional variables of Modula-2 were found difficult to inherit. |
<XDS Modula-2>
Run in the XDS environment with TopSpeed extension and Hgraph graphics package.
|
Decision-Making Steps | |
<Reflection and Termination>
When traversing in a straight line, next icon is always found with the value of dircn (all True) kept fixed. However, on the boundaries the property does not hold true, and the next appropriate value of dircn has to be sought for using PROCEDURE checkNeighbor(VAR next: INTEGER; prevN: INTEGER; prevdircn: INTEGER): BOOLEAN;This procedure effectively takes into account the table of dpi4 shown at right. As a matter of fact another set of the dpi4 values for 0 rad, ƒÎ/2 rad, ƒÎ rad and 3ƒÎ/2 rad are necessary for the automatic determination of reflecton direction. |
<Values of 'dircn' at various positions>
|
<Sequences of Infinite Lengths>
If the number of icons tends to exceed the predetermined memory capacity, the sequence should be understood as continuing indefinitely. Such a sequence is illustrated at right. It consisits of a leading sequence of length Lini (=5 in the figure)and a repetition of the finite sequence of length Lrep (=6), which may be called period. |
<An infinite sequence composed of two types of finite sequences>
|
Infinite Sequence for H=12, W=6 and A=3 | |
< Python > | < XDS Modula-2 > |