Skip to content

Instantly share code, notes, and snippets.

View Shaddy's full-sized avatar

Sherab Giovannini Shaddy

View GitHub Profile
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()
}
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;
@Shaddy
Shaddy / triangle_finder.rs
Created August 3, 2017 11:25
Pythagoras problem
#![feature(conservative_impl_trait)] // this requires nigthly version
#[macro_use]
extern crate itertools;
#[derive(Debug)]
struct Triangle {
a: u32,
b: u32,
c: u32,