mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 13:44:15 +00:00
Improve output of factorization
This commit is contained in:
parent
e54edca635
commit
e1b7e3ab5e
1 changed files with 9 additions and 0 deletions
|
@ -574,6 +574,15 @@ impl Context {
|
|||
let mut results = results.into_sorted_vec();
|
||||
results.dedup();
|
||||
let results = results.into_iter().map(|Factors(_score, names)| {
|
||||
let mut next = BTreeMap::<Rc<String>, usize>::new();
|
||||
for name in names.into_iter() {
|
||||
*next.entry(name).or_insert(0) += 1;
|
||||
}
|
||||
let names = next.into_iter().map(|(a, b)| if b > 1 {
|
||||
Rc::new(format!("{}^{}", a, b))
|
||||
} else {
|
||||
a
|
||||
}).collect::<Vec<_>>();
|
||||
let first = names.first().cloned();
|
||||
names.into_iter().skip(1).fold(
|
||||
first.map(|x| (**x).to_owned()).unwrap_or(String::new()),
|
||||
|
|
Loading…
Reference in a new issue