Skip to content

Instantly share code, notes, and snippets.

@AnthonyMikh
Last active May 22, 2018 11:34
Show Gist options
  • Save AnthonyMikh/ee56636ec95863629b5b8f7578a2fdc2 to your computer and use it in GitHub Desktop.
Save AnthonyMikh/ee56636ec95863629b5b8f7578a2fdc2 to your computer and use it in GitHub Desktop.
Решение задачи №95 от UniLecs (без обработки ошибок)
//Для удобства, чтобы мерить площадь в долях пи, а не напрямую
//в квадратных единицах
#[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));
}
@AnthonyMikh
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment