Last active
May 22, 2018 11:34
-
-
Save AnthonyMikh/ee56636ec95863629b5b8f7578a2fdc2 to your computer and use it in GitHub Desktop.
Решение задачи №95 от UniLecs (без обработки ошибок)
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
//Для удобства, чтобы мерить площадь в долях пи, а не напрямую | |
//в квадратных единицах | |
#[derive(Debug, PartialEq)] | |
struct PiFractions(f64); | |
impl ::std::convert::Into<f64> for PiFractions { | |
fn into(self) -> f64 { | |
self.0 * ::std::f64::consts::PI | |
} | |
} | |
//Входные данные | |
enum HoledCircle { | |
Radiuses(f64, f64), //радиусы внутренних окружностей | |
Chord(f64), //длина хорды | |
} | |
fn holed_circle_area(input: &HoledCircle) -> PiFractions { | |
use HoledCircle::*; | |
match input { | |
Radiuses(r1, r2) => PiFractions(2.0 * r1 * r2), | |
Chord(t) => PiFractions(t * t / 8.0), | |
} | |
} | |
fn main() { | |
use HoledCircle::*; | |
assert_eq!(holed_circle_area(&Radiuses(3.0, 4.0)), PiFractions(24.0)); | |
assert_eq!(holed_circle_area(&Chord(4.0)), PiFractions(2.0)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Playground: http://play.rust-lang.org/?gist=f9b9ebf5f5da78f8f3e94f77b145f385&version=stable&mode=debug