UP | HOME
../../

Prog Exercises

1 Cutting Up a Chess Board into L-shapes

prog-exercise-1.png

On a chessboard of size 8 x 8, the square at position (x, y) is cut off. Write a program, which will cut the rest of the chessboard into L-shaped fragments (3 adjacent squares). Example: Cut-off square at (1, 4) should result in the figure. [Found on Quora.com 2016]

2 Tomohiko Sakamoto's Algorithm

Apparently the following computes the day of week from any given date.

int dow(int y, int m, int d) {
    static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
    y -= m < 3;
    return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}

2.1 Exercise

  1. Specify it.
  2. Explain it. Including "static".
  3. Is it kosher to alter y?

3 References


Copyright © 2016 pmateti@wright.edu www.wright.edu/~pmateti 2016-05-29