use std::path::Path; use std::fs::File; use std::io::{BufRead, BufReader}; use fqdn::FQDN; fn main() { // Create a path to the desired file let path = Path::new("/Users/xophe/Logiciels/TESS/Antidote/mudkeys"); // Open the path in read-only mode, returns `io::Result` // Open the path in read-only mode, returns `io::Result` let file = File::open(&path).unwrap(); let reader = BufReader::new(file); let mut letter = [0u32; 256]; reader.lines() .map(|line| line.unwrap().parse::()) .filter_map(|x| x.ok()) .for_each(|f| { let c = f.as_bytes()[f.as_bytes().len()-2].to_ascii_lowercase(); letter[c as usize] += 1 }); let mut freq = letter.iter().enumerate() .filter(|(_,c)| **c > 0) .collect::>(); freq.sort_by_key(|(_,c)| **c); freq.iter().rev().for_each(|(i,_)| print!("{} ", *i as u8 as char)); } /* s.as_bytes().iter() .for_each(|c| letter[c.to_ascii_lowercase() as usize] += 1); let mut freq = letter.iter() .enumerate() .map(|(c, n)| (c as u8 as char, *n)) .filter(|(c, n)| *n > 0 && *c != '\n' && *c != ':') .collect::>(); freq.sort_by_key(|(_, n)| *n); let mut iter = freq.iter().map(|(c, _)| c).rev(); let mut group = [[' '; 7]; 7]; group.iter_mut().for_each(|a| a[0] = *iter.next().unwrap()); group.iter_mut().rev() .try_for_each(|a| a.iter_mut() .skip(1) .try_for_each(|slot| match iter.next() { Some(c) => { *slot = *c; Ok(()) } None => Err(()) } ) ); group.iter().for_each(|a| { a.iter().for_each(|c| print!("{}, ", c)); println!(); }); let mut mapping = [(0u8,0u8);256]; group.iter().enumerate().for_each(|(i, a)| a.iter().enumerate().filter(|(_,c)| **c != ' ').for_each(|(j, c)| { mapping[c.to_ascii_lowercase() as usize] = (i as u8,j as u8); mapping[c.to_ascii_uppercase() as usize] = (i as u8,j as u8); }) ); let mut iter = mapping.iter(); /* pub(crate) const ALPHABET: [u8;256] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,37, 0, 0, // 48 (-) 27,28,29,30,31,32,33,34, 35,36, 0, 0, 0, 0, 0, 0, // 64 (0-9) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15, // 80 (A-O) 16,17,18,19,20,21,22,23, 24,25,26, 0, 0, 0, 0,__, // 96 (P-Z et _) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15, // 112 (a-o) 16,17,18,19,20,21,22,23, 24,25,26, 0, 0, 0, 0, 0, // 128 (p-z) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];*/ (0..16).into_iter().for_each(|_| { print!(" "); (0..2).into_iter().for_each(|_| { (0..8).into_iter().for_each(|_| { let (i,j) = iter.next().unwrap(); print!("({},{}), ", i, j ); }); print!(" "); }); println!(); }); } /* . -> 313880 o -> 227943 c -> 209144 u -> 146074 k -> 139188 m -> 117944 n -> 99949 i -> 95889 e -> 95533 a -> 93225 t -> 88272 d -> 86480 r -> 83421 s -> 81496 p -> 78078 g -> 74977 b -> 72425 l -> 70962 h -> 65631 f -> 64456 v -> 63131 y -> 62057 w -> 61868 x -> 59532 j -> 59206 q -> 56721 z -> 25748 - -> 9113 1 -> 7828 0 -> 7503 2 -> 7171 3 -> 6527 7 -> 5472 4 -> 5397 5 -> 5351 6 -> 4823 9 -> 4338 8 -> 4210 _ -> 91 Process finished with exit code 0 */*/