Skip to content

Instantly share code, notes, and snippets.

View another
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()
}
View lib.rs
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;
View triangle_finder.rs
#![feature(conservative_impl_trait)] // this requires nigthly version
#[macro_use]
extern crate itertools;
#[derive(Debug)]
struct Triangle {
a: u32,
b: u32,
c: u32,