#!/usr/bin/perl
use 5.016;
use warnings;
my @board = ([0]);
sub check_on_board {
(
($_[0] >= 0) and ($_[1] >= 0) and
($_[0] < 8) and ($_[1] < 8) and
(not defined $board[$_[1]]->[$_[0]])
$board[$_[1]]->[$_[0]] = $_[2];
}
sub f {
my @queue = ([0, 0, 0]);
while(@queue){
my ($x, $y, $n) = @{shift @queue};
foreach(
[-2, -1], [-2, 1],
[-1, -2], [ 1, -2],
[ 2, -1], [ 2, 1],
[-1, 2], [ 1, 2],
){
if (check_on_board($x + $_->[0], $y + $_->[1], $n + 1)){
push @queue, [$x + $_->[0], $y + $_->[1], $n + 1]; }
}
}
}
f();
foreach(@board){
say @{$_};
}
IyEvdXNyL2Jpbi9wZXJsCnVzZSA1LjAxNjsKdXNlIHdhcm5pbmdzOwoKbXkgQGJvYXJkID0gKFswXSk7CgpzdWIgY2hlY2tfb25fYm9hcmQgewoJKAoJCSgkX1swXSA+PSAwKSBhbmQgKCRfWzFdID49IDApIGFuZAoJCSgkX1swXSA8ICA4KSBhbmQgKCRfWzFdIDwgIDgpIGFuZAoJCShub3QgZGVmaW5lZCAkYm9hcmRbJF9bMV1dLT5bJF9bMF1dKQoJKSBvciByZXR1cm47CgoJJGJvYXJkWyRfWzFdXS0+WyRfWzBdXSA9ICRfWzJdOwoKCXJldHVybiAxOwp9CgpzdWIgZiB7CglteSBAcXVldWUgPSAoWzAsIDAsIDBdKTsKCgl3aGlsZShAcXVldWUpewoJCW15ICgkeCwgJHksICRuKSA9IEB7c2hpZnQgQHF1ZXVlfTsKCgkJZm9yZWFjaCgKCQkJWy0yLCAtMV0sIFstMiwgIDFdLAoJCQlbLTEsIC0yXSwgWyAxLCAtMl0sCgkJCVsgMiwgLTFdLCBbIDIsICAxXSwKCQkJWy0xLCAgMl0sIFsgMSwgIDJdLAoJCSl7CgkJCWlmIChjaGVja19vbl9ib2FyZCgkeCArICRfLT5bMF0sICR5ICsgJF8tPlsxXSwgJG4gKyAxKSl7CgkJCQlwdXNoIEBxdWV1ZSwgWyR4ICsgJF8tPlswXSwgJHkgKyAkXy0+WzFdLCAkbiArIDFdOwoJCQl9CgkJfQoJfQp9CgpmKCk7Cgpmb3JlYWNoKEBib2FyZCl7CglzYXkgQHskX307Cn0K