Skip to content

Commit

Permalink
Fix a math mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
uellenberg committed Nov 29, 2023
1 parent 613c652 commit 942228e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sections/60_continuing_cs/00_recursion_intro/counting.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function countFor(num) {
// It's also worth noting that, for this problem, there's an even simpler (and faster) way to write it: math.
function countMath(num) {
// https://en.wikipedia.org/wiki/Arithmetic_progression#Sum
return num * (num - 1) / 2;
return num * (num + 1) / 2;
}

// Let's give these functions a try!
Expand Down

0 comments on commit 942228e

Please sign in to comment.