Created
June 5, 2021 17:31
-
-
Save claudioacioli/417e6061c1f6baad702812dcc1915d99 to your computer and use it in GitHub Desktop.
Solve me first (https://www.hackerrank.com/challenges/solve-me-first/problem)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
fn main() { | |
let mut input = String::new(); | |
io::stdin().read_line(&mut input).unwrap_or(0); | |
let a = input.trim().parse::<u16>().unwrap_or(0); | |
input.clear(); | |
io::stdin().read_line(&mut input).unwrap_or(0); | |
let b = input.trim().parse::<u16>().unwrap_or(0); | |
if a < 1 || a > 100 || b < 1 || b > 100 { | |
println!("Please insert numbers with 1 and 100"); | |
return; | |
} | |
println!("{}", solve_me_first(a, b)); | |
} | |
fn solve_me_first(a:u16, b:u16) -> u16 { | |
a + b | |
} | |
#[test] | |
fn test_solve_me_first() { | |
assert_eq!(10, solve_me_first(5, 5)); | |
assert_eq!(10, solve_me_first(2, 8)); | |
assert_eq!(5, solve_me_first(1, 4)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment