We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 56753cf commit e5a36d6Copy full SHA for e5a36d6
2501-2600/2579_count_total_number_of_colored_cells.rb
@@ -0,0 +1,10 @@
1
+# @param {Integer} n
2
+# @return {Integer}
3
+def colored_cells(n)
4
+ # from top cell to the mid line
5
+ # count = 1 + 3 + 5 + ... + (2n - 1) = n**2
6
+ # the same as from bottom cell to the mid line
7
+ # but the mid line is duplicate
8
+ # so 2 * count - the-mid-line-count
9
+ 2 * n**2 - (2*n - 1)
10
+end
0 commit comments