Created
May 5, 2017 03:37
-
-
Save asolkar/1e1f9e4870d2948d8cf668dbcf8ecbd5 to your computer and use it in GitHub Desktop.
Squares in a checkerboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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