No such thing as a small change PerlMonks

### comment on

 Need Help??
Before I went to bed, I only had a guess. I started with a pen and paper, and some maths:
```              w * h = (w - 2) * h + 10
w * h - (w - 2) - h = 10
h * (w - w + 2) = 10
2h = 10
h = 5

Now, we need to find the width. To be able to step on every tile, it must be coprime with the height, and moreover, width - 2 must be coprime with the height as well. I drew the simplest cases and extrapolated the observation to the following sequence: 3, 9, 11, 13, 19, 21, 23...

And when I got up, I verifyied the results with a Perl program. Specify a true command line argument to see the paths:

```#!/usr/bin/perl
use strict;
use warnings;

my \$DEBUG = shift;

sub steps {
my (\$w, \$h) = @_;
print "\$w x \$h\n" if \$DEBUG;
my \$steps = 1;
my @dir = ( 1, 1 );
my (\$x, \$y) = (1, 1);
my @visited = ([], [ undef, '\\' ]);
while () {
\$x += \$dir[0];
\$y += \$dir[1];
\$dir[0] = -1, \$x -= 1 if \$x > \$w;
\$dir[1] = -1, \$y -= 1 if \$y > \$h;
\$dir[0] = 1,  \$x = 1  if \$x < 1;
\$dir[1] = 1,  \$y = 1  if \$y < 1;
++\$steps;
return -1 if \$steps > \$w * \$h or \$visited[\$x][\$y];

\$visited[\$x][\$y] = \$dir[0] != \$dir[1] ? '/' : '\\';
if (\$DEBUG) {
for my \$x (1 .. \$w) {
for my \$y (1 .. \$h) {
print \$visited[\$x][\$y] // ' ';
}
print "\n";
}
sleep 1;
print "\n";
}

if (\$x == \$w and \$y == \$h) {
last if \$steps == \$w * \$h
and '\\' eq \$visited[\$x][\$y];

return -1
}
}
return \$steps
}

my @steps;
my \$width = 1;
until (0) {
for my \$height (1 .. \$width) {
\$steps[\$width][\$height] = steps(\$width, \$height);
print "\$width x \$height = \$steps[\$width][\$height]\n"
if (\$height > 2          and \$steps[\$width][\$height - 2] =
+= \$steps[\$width][\$height] - 10)
or (\$height < \$width - 1 and \$steps[\$width - 2][\$height] =
+= \$steps[\$width][\$height] - 10)
}
++\$width;
}
Update: Spoiler tag removed.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-08-10 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When will the AI bubble burst?

Results (21 votes). Check out past polls.

Notices?
 • erzuuli ‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.