Guest User

Untitled

a guest
Jan 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. use std::fmt::Write;
  2.  
  3. fn main() {
  4. two()
  5. }
  6.  
  7. fn one() {
  8. let mut count : u64 = 0;
  9. let until = 1e6 as u64;
  10. for i in 1..until {
  11. let s = i.to_string();
  12. if s.contains("3") {
  13. count+=1;
  14. }
  15. }
  16. println!("Count until {}: {}", until, count);
  17.  
  18. }
  19.  
  20. fn two() {
  21. let mut count : u64 = 0;
  22. let until = 1e6 as u64;
  23. let mut s = String::with_capacity(10);
  24. for i in 1..until {
  25. s.clear();
  26. write!(s, "{}", i).unwrap();
  27. if s.contains("3") {
  28. count+=1;
  29. }
  30. }
  31. println!("Count until {}: {}", until, count);
  32. }
Add Comment
Please, Sign In to add comment