Browse Source

057 begin

master
Coin de Gamma 10 months ago
parent
commit
9c9e04bb98
  1. 33
      057/main.rs

33
057/main.rs

@ -0,0 +1,33 @@
struct D {
a: u32,
b: u32
}
impl D {
pub fn from(a: u32, b: u32) -> D {
D { a: a, b: b }
}
pub fn print(&self) {
println!("{}/{}", self.a, self.b);
}
pub fn add_n(&self, n: u32) -> D {
let aa = self.b;
return D::from(aa + self.a, self.b);
}
pub fn iter(&self) -> D {
let mut res = self.add_n(1);
let dd = D::from(res.b, res.a);
return dd.add_n(1);
}
}
fn main() {
let mut d = D::from(1, 2);
d = d.add_n(1);
d.print();
for n in 0..100 {
d = d.iter();
d.print();
}
}
Loading…
Cancel
Save