diff options
| author | Federico Igne <git@federicoigne.com> | 2020-12-26 17:48:38 +0000 |
|---|---|---|
| committer | Federico Igne <git@federicoigne.com> | 2021-11-03 18:55:08 +0000 |
| commit | 02481656966b0a8dfc95cf3c22bcc049660ff7d4 (patch) | |
| tree | 8e39798fcaf27931d91c2088423fd4e97adcfc2d /difference-of-squares/src/lib.rs | |
| parent | 4e2052c4d792540c2f742b2c2a081b11117ed41d (diff) | |
| download | exercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.tar.gz exercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.zip | |
Move Rust exercises in a subdirectory
Diffstat (limited to 'difference-of-squares/src/lib.rs')
| -rw-r--r-- | difference-of-squares/src/lib.rs | 14 |
1 files changed, 0 insertions, 14 deletions
diff --git a/difference-of-squares/src/lib.rs b/difference-of-squares/src/lib.rs deleted file mode 100644 index 4599733..0000000 --- a/difference-of-squares/src/lib.rs +++ /dev/null | |||
| @@ -1,14 +0,0 @@ | |||
| 1 | /// Implements square of Gauss' formula | ||
| 2 | pub fn square_of_sum(n: u32) -> u32 { | ||
| 3 | (n * (n + 1) / 2).pow(2) | ||
| 4 | } | ||
| 5 | |||
| 6 | /// Implements the formula reported in Wolfram|Alpha at this | ||
| 7 | /// [link](https://www.wolframalpha.com/input/?i=sum+of+squares&assumption=%7B%22F%22%2C+%22SumOfSquaresOfIntegers%22%2C+%22sumlowerlimit%22%7D+-%3E%221%22&assumption=%7B%22F%22%2C+%22SumOfSquaresOfIntegers%22%2C+%22sumupperlimit2%22%7D+-%3E%22n%22) | ||
| 8 | pub fn sum_of_squares(n: u32) -> u32 { | ||
| 9 | n * (1 + n) * (1 + 2 * n) / 6 | ||
| 10 | } | ||
| 11 | |||
| 12 | pub fn difference(n: u32) -> u32 { | ||
| 13 | square_of_sum(n) - sum_of_squares(n) | ||
| 14 | } | ||
