I’ve been doing the Weekly
Challenges. The
latest
involved an old friend and extensive string manipulation. (Note that
this ends today.)
Task 1: Chessboard Squares
You are given two coordinates of a square on 8x8 chessboard.
Write a script to find the given two coordinates have the same colour.
It amused me to write this as a wrapper round the solution to
challenge 281 task 1, which determined the colour of a square.
So in Perl I already had:
sub cs2xy($a) {
my @c = split('', $a);
my $x = ord($c[0]) - ord('a');
my $y = ord($c[1]) - ord('1');
return [$x, $y];
}
sub checkcolor($a) {
my $xy = cs2xy($a);
return (($xy->[0] + $xy->[1]) % 2 == 1)?1:0;
}
and all I had to do was wrap the latter:
sub chessboardsquares($a, $b) {
(checkcolor($a) == checkcolor($b))?1:0;
}
Well, I've added Scala and Typst since #281, so that was all fresh code.
I didn't have the enthusiasm to tackle part 2, and I do this for fun.
Full code on
codeberg.
Comments on this post are now closed. If you have particular grounds for adding a late comment, comment on a more recent post quoting the URL of this one.