Calculate sum of remaining squares in current row by removing the leftmost strip of previous sub - square and adding a new strip
for ( $ j = 1 ; $ j < $ n - $ k + 1 ; $ j ++ ) { $ sum += ( $ stripSum [ $ i ] [ $ j + $ k - 1 ] - $ stripSum [ $ i ] [ $ j - 1 ] ) ; echo $ sum , " " ; } echo " STRNEWLINE " ; } }