Skip to content

Instantly share code, notes, and snippets.

@marioidival
Last active April 6, 2018 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marioidival/5fa6b8b21f3bfb2136dea2eea3fd15c9 to your computer and use it in GitHub Desktop.
Save marioidival/5fa6b8b21f3bfb2136dea2eea3fd15c9 to your computer and use it in GitHub Desktop.
Solve challenges in Rust
/// Found palindrome numeric
fn is_palindrome_numeric(n: String) -> bool {
n == n.chars().rev().collect::<String>()
}
fn main() {
for i in 1..20 {
if is_palindrome_numeric(format!("{}", i)) {
println!("{}", i)
}
}
}
/// Solve prime number with Sieve of Eratosthenes
fn sieve(list: &[i64]) {
if let Some((head, tail)) = list.split_first() {
let ys: Vec<i64> = tail.iter().filter(|n| *n % head != 0).cloned().collect();
print!("{}, ", head);
sieve(&ys[..]);
}
}
fn main() {
let numbers: Vec<i64> = (2..10_000).map(|n| n).collect();
sieve(&numbers[..]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment