#!/usr/bin/perl -w

use strict;
use v5.30;

my $in = 1362;
# my $in = 10;

my %maze;
$; = ',';
sub is_wall {
	my ($x, $y) = @_;
	return $maze{$x,$y} if exists $maze{$x,$y};

	my $sum = $in + $x*$x + 3*$x + 2*$x*$y + $y + $y*$y;
	my $bin = sprintf("%b", $sum);
	say "$x $y => $sum => $bin";
	my $count = () = $bin =~ /1/g;
	return $maze{$x,$y} = $count & 1;
}

say is_wall(0, 0);
say is_wall(3, 5);
say is_wall(9, 2);

my %seen = ( "1,1" => 1 );
my @paths = ( [ 1, 1, 0 ] );
while (@paths) {
	my $p = shift @paths;
	my ($x, $y, $steps) = @$p;
	for my $d ([0, 1], [0, -1], [1, 0], [-1, 0]) {
		my $x1 = $x + $d->[0];
		my $y1 = $y + $d->[1];
		next if $x1 < 0 || $y1 < 0;
		next if $seen{$x1,$y1};
		next if is_wall($x1, $y1);
		next if $steps >= 50;
		$seen{$x1,$y1}++;
		push @paths, [$x1, $y1, $steps+1];
	}
}
say scalar keys %seen;
