http://www.perlmonks.org?node_id=1121552

BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

Whilst waiting for my tea to brew, and thinking about my latest programming problem, I found myself 'walking the diagonals' on my tiled kitchen floor.

Walking the diagonals means starting in one corner of the rectangle and walking away at 45 degrees:

```+---+---+---
| \ |   |
+---+---+---
|   | \ |
+---+---+---
|   |   | \

And when you hit the opposite edge, 'reflect' back in the other direction:

```   | \ |   |   | / |
---+---+---+---+---+
|   | \ | / |   |
+---+---+---+---+---

Ditto at the ends:

```|   | / |
+---+---+---
| / |   | /
+---+---+---+
| \ | / |
+---+---+---+

The walk ends when you arrive directly into a corner. See the first diagram, but going the other way.

What I noticed was that starting in one corner, and continuing until I encountered another corner, I found myself in the diagonally opposite corner. When I drew a diagram on a post-it, I discovered that I had walked on every tile exactly once.

This was interesting, because I've been doing this 'walking the diagonals' when deep in thought -- a mindless repetitious activity that frees the mind for deeper things -- and recalled that in my old house kitchen, where the rectangle was the same width, but 2 tiles shorter, the tour also ended up in the opposite diagonal; also covered every tile exactly once and was 14 10 steps smaller.

How big is the rectangle in my current kitchen? Answer: 13 x 5.

(Other answers are possible, particularly 5x9 solution; but most of them would either have required me to use one of the terms: 'kitchenette' or 'galley' (as in train or ship) rather than kitchen :)

I was going to post code, but choroba's is much prettier; especially if you a) stop it considering even numbers; b) add a system 'cls'; or equivalent into the redraw loop; c) reduce the sleep time after the for loop to 1/10th second. Quite hypnotic once the sizes get up a bit (I start it at 21 and inc by 2).

Solution:

```Old: 5x11

s/\/\/\/\/\
/\/\/\/\/\/
\/\/\/\/\/\
/\/\/\/\/\/
\/\/\/\/\/e

New: 5x13

s/\/\/\/\/\/\
/\/\/\/\/\/\/
\/\/\/\/\/\/\
/\/\/\/\/\/\/
\/\/\/\/\/\/e