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.
Note that I will only approve comments that relate to the blog post itself, not ones that relate only to previous comments. This is to ensure that the blog remains outside the scope of the UK's Online Safety Act (2023).
Your submission will be ignored if any field is left blank, but your email address will not be displayed. Comments will be processed through markdown.