l8kyu/
math.rs

1//!
2//! Modules categorized by Codewars labels - 8kyu *** Mathematics ***
3//!
4
5use shared::kata::*;
6
7/// Write a program that finds the summation of every number from 1 to num.
8/// The number will always be a positive integer greater than 0.
9/// Using Arithmetic Series Sum Formula - Carl Friedrich Gauss.
10/// # Example
11/// ``` summation(8); ``` <br>
12/// returns 36
13pub fn summation(n: i32) -> i32 {
14    let kata = Kata {
15        level: Level::L8kyu,
16        tags: vec![Tag::Fundamentals, Tag::Mathematics],
17        description: String::from("Grasshopper - Summation"),
18    };
19
20    println!(
21        "Level: {:?}, Tags: {:?}, Description: {}",
22        kata.level, kata.tags, kata.description
23    );
24    
25    n*(n+1)/2
26}