Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. struct Fibonacci {
  2. current: u64,
  3. next: u64
  4. }
  5.  
  6. impl Iterator for Fibonacci {
  7. type Item = u64;
  8. fn next(&mut self) -> Option<u64> {
  9. let n = self.current + self.next;
  10. self.current = self.next;
  11. self.next = n;
  12. Some(self.current)
  13. }
  14. }
  15.  
  16. fn main() {
  17. let f = Fibonacci {
  18. current: 1,
  19. next: 1
  20. };
  21. for n in f.take(91) {
  22. println!("{}", n);
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement