Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backtracking/sudoku.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Sudoku {
}

fn find_empty_cell(&self) -> Option<(usize, usize)> {
// Find a empty cell in the board (returns (-1, -1) if all cells are filled)
// Find a empty cell in the board (returns None if all cells are filled)
for i in 0..9 {
for j in 0..9 {
if self.board[i][j] == 0 {
Expand Down
2 changes: 2 additions & 0 deletions src/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub mod sieve_of_eratosthenes;
mod signum;
mod simpson_integration;
mod sine;
mod square_pyramidal_numbers;
mod square_root;
mod sum_of_digits;
mod trial_division;
Expand Down Expand Up @@ -91,6 +92,7 @@ pub use self::sieve_of_eratosthenes::sieve_of_eratosthenes;
pub use self::signum::signum;
pub use self::simpson_integration::simpson_integration;
pub use self::sine::sine;
pub use self::square_pyramidal_numbers::square_pyramidal_number;
pub use self::square_root::{fast_inv_sqrt, square_root};
pub use self::sum_of_digits::{sum_digits_iterative, sum_digits_recursive};
pub use self::trial_division::trial_division;
Expand Down
20 changes: 20 additions & 0 deletions src/math/square_pyramidal_numbers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// https://en.wikipedia.org/wiki/Square_pyramidal_number
// 1² + 2² + ... = ... (total)

pub fn square_pyramidal_number(n: u64) -> u64 {
n * (n + 1) * (2 * n + 1) / 6
}

#[cfg(test)]
mod tests {

use super::*;

#[test]
fn test0() {
assert_eq!(0, square_pyramidal_number(0));
assert_eq!(1, square_pyramidal_number(1));
assert_eq!(5, square_pyramidal_number(2));
assert_eq!(14, square_pyramidal_number(3));
}
}