space-age
This commit is contained in:
parent
498f64b5cd
commit
d3bfaf4131
7 changed files with 394 additions and 0 deletions
71
rust/space-age/src/lib.rs
Normal file
71
rust/space-age/src/lib.rs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
// The code below is a stub. Just enough to satisfy the compiler.
|
||||
// In order to pass the tests you can add-to or change any of this code.
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Duration {
|
||||
seconds: u64,
|
||||
}
|
||||
|
||||
impl From<u64> for Duration {
|
||||
fn from(s: u64) -> Self {
|
||||
Self { seconds: s }
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Planet {
|
||||
fn years_during(d: &Duration) -> f64 {
|
||||
(d.seconds as f64 / 60.0 / 60.0 / 24.0) / 365.25 / Self::period()
|
||||
}
|
||||
fn period() -> f64;
|
||||
}
|
||||
|
||||
pub struct Mercury;
|
||||
pub struct Venus;
|
||||
pub struct Earth;
|
||||
pub struct Mars;
|
||||
pub struct Jupiter;
|
||||
pub struct Saturn;
|
||||
pub struct Uranus;
|
||||
pub struct Neptune;
|
||||
|
||||
impl Planet for Mercury {
|
||||
fn period() -> f64 {
|
||||
0.2408467
|
||||
}
|
||||
}
|
||||
impl Planet for Venus {
|
||||
fn period() -> f64 {
|
||||
0.61519726
|
||||
}
|
||||
}
|
||||
impl Planet for Earth {
|
||||
fn period() -> f64 {
|
||||
1.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Planet for Mars {
|
||||
fn period() -> f64 {
|
||||
1.8808158
|
||||
}
|
||||
}
|
||||
impl Planet for Jupiter {
|
||||
fn period() -> f64 {
|
||||
11.862615
|
||||
}
|
||||
}
|
||||
impl Planet for Saturn {
|
||||
fn period() -> f64 {
|
||||
29.447498
|
||||
}
|
||||
}
|
||||
impl Planet for Uranus {
|
||||
fn period() -> f64 {
|
||||
84.016846
|
||||
}
|
||||
}
|
||||
impl Planet for Neptune {
|
||||
fn period() -> f64 {
|
||||
164.79132
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue