This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn wilson_primes(n: usize) -> Vec<usize> { | |
let mut f = 1; | |
(2..n).map(move |n| { | |
f *= n - 1; | |
n}) | |
.filter(|&n| ((f + 1) % n == 0)) | |
.collect() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::{HashMap, HashSet}; | |
pub fn word_count(input: &str) -> HashMap<String, u32> { | |
let mut map: HashMap<String, u32> = HashMap::new(); | |
let words: Vec<&str> = input.split_whitespace().collect(); | |
let set: HashSet<&str> = words.clone().into_iter().collect::<HashSet<&str>>(); | |
for word in set { | |
let count = words.iter().filter(|&w| *w == word).count() as u32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(conservative_impl_trait)] // this requires nigthly version | |
#[macro_use] | |
extern crate itertools; | |
#[derive(Debug)] | |
struct Triangle { | |
a: u32, | |
b: u32, | |
c: u32, |