Initial commit

This commit is contained in:
Valentin Brandl
2018-10-13 13:23:37 +02:00
commit 1ad2f0e3ab
32 changed files with 2541 additions and 0 deletions

View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

View File

@ -0,0 +1,32 @@
[[package]]
name = "countmap"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "u01"
version = "0.1.0"
dependencies = [
"countmap 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum countmap 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ef2a403c4af585607826502480ab6e453f320c230ef67255eee21f0cc72c0a6"
"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"

View File

@ -0,0 +1,7 @@
[package]
name = "u01"
version = "0.1.0"
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
[dependencies]
countmap = "0.2.0"

View File

@ -0,0 +1,81 @@
extern crate countmap;
use countmap::CountMap;
use std::{
fs::File,
io::{BufRead, BufReader},
};
fn count() {
let args: Vec<_> = std::env::args().collect();
let file = args.get(1).unwrap();
let mut map: CountMap<char, u32> = CountMap::new();
let read = BufReader::new(File::open(file).unwrap());
for line in read.lines() {
if let Ok(line) = line {
line.chars().filter(|c| c.is_alphabetic()).for_each(|c| {
map.insert_or_increment(c);
});
}
}
let sum: u32 = map
.iter()
.filter(|(k, _)| k.is_alphabetic())
.map(|(_, v)| v)
.sum();
let mut vec: Vec<_> = map.into_iter().collect();
vec.sort_unstable();
vec.into_iter().for_each(|(k, v)| {
println!(
"{} &\\text{{:}}& {:3} \\to{{}} {:.2} \\\\",
k,
v,
v as f64 / sum as f64
)
});
println!("sum &\\text{{:}}& {}", sum);
}
fn main() {
let args: Vec<_> = std::env::args().collect();
let file = args.get(1).unwrap();
let read = BufReader::new(File::open(file).unwrap());
for line in read.lines() {
if let Ok(line) = line {
let s: String = line
.chars()
.map(|c| match c {
'A' => 'f',
'B' => 'ä',
'C' => 'g',
'D' => 'j',
'E' => 'ö',
'F' => 'x',
'G' => 'n',
'J' => 'i',
'K' => 'm',
'L' => 'c',
'M' => 'ß',
'N' => 'v',
'O' => 'd',
'P' => 'r',
'Q' => 'a',
'R' => 'l',
'S' => 'e',
'T' => 'ü',
'U' => 'h',
'V' => 'z',
'W' => 't',
'X' => 'w',
'Y' => 'p',
'Z' => 's',
'Ä' => 'o',
'Ö' => 'b',
'Ü' => 'u',
'ß' => 'k',
c => c,
}).collect();
println!("{}", s);
}
}
}