Skip to content

Instantly share code, notes, and snippets.

@sumproxy
Last active October 13, 2015 07:54
Show Gist options
  • Save sumproxy/0dc392cba936a31c8649 to your computer and use it in GitHub Desktop.
Save sumproxy/0dc392cba936a31c8649 to your computer and use it in GitHub Desktop.
extern crate itertools;
use itertools::Itertools;
use std::thread;
use std::sync::{Mutex, Arc};
fn is_palindrome(num: u64) -> bool {
let s = num.to_string();
s.chars().zip(s.chars().rev()).all(|(i1, i2)| i1 == i2 )
}
fn main() {
let mut iter = Arc::new(Mutex::new((100..1000).combinations()));
for _ in 0..8 {
let iter = iter.clone();
thread::spawn(move || {
let mut block = iter.lock().unwrap().take(10000);
while block.len() > 0 {
for tup in block {
//TODO
}
let mut block = iter.lock().unwrap().take(10000);
}
});
}
}
@sumproxy
Copy link
Author

Compiling palindrome v0.1.0 (file:///Users/SumProxy/Projects/rust/palindrome)
src/main.rs:17:25: 17:30 error: no method named `len` found for type `core::iter::Take<itertools::adaptors::Combinations<core::ops::Range<_>>>` in the current scope
src/main.rs:17             while block.len() > 0 {
                                       ^~~~~
note: in expansion of closure expansion
src/main.rs:15:23: 23:10 note: expansion site
note: in expansion of for loop expansion
src/main.rs:13:5: 24:6 note: expansion site
src/main.rs:17:25: 17:30 note: the method `len` exists but the following trait bounds were not satisfied: `itertools::adaptors::Combinations<core::ops::Range<_>> : core::iter::ExactSizeIterator`
error: aborting due to previous error
Could not compile `palindrome`.

To learn more, run the command again with --verbose.

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