Skip to content

Instantly share code, notes, and snippets.

@manjeettahkur
Last active February 10, 2024 08:20
Show Gist options
  • Save manjeettahkur/131bb6bf2d3fe51c1add to your computer and use it in GitHub Desktop.
Save manjeettahkur/131bb6bf2d3fe51c1add to your computer and use it in GitHub Desktop.
Given the triangle of consecutive odd numbers
Description:
Given the triangle of consecutive odd numbers:
1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
...
function rowSumOddNumbers(n) {
return Math.pow(n, 3);
}
function rowSumOddNumbers(n) {
return n*n*n
}
@Xlizer1
Copy link

Xlizer1 commented Feb 10, 2024

Nice kata thanks @AceTheCreator for the explanation, I might have never discovered the algorithm. It is 2 lines in SQL

select n*n*n "res"
from nums ;

or in one line using javascript:

const rowSumOddNumbers = n => n ** 3;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment