Skip to content

Instantly share code, notes, and snippets.

@asolkar
Created May 5, 2017 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asolkar/1e1f9e4870d2948d8cf668dbcf8ecbd5 to your computer and use it in GitHub Desktop.
Save asolkar/1e1f9e4870d2948d8cf668dbcf8ecbd5 to your computer and use it in GitHub Desktop.
Squares in a checkerboard
#!/usr/bin/perl
use strict;
use warnings;
my $m = shift @ARGV;
my $sqrs = 0;
#
# n=m
# (
# / (m-n+1)^2
# )
# n=1
for my $n (1..$m) {
$sqrs += ($m - $n + 1) * ($m - $n + 1);
}
print "Checkerboard of ($m x $m) has $sqrs squares\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment