Skip to content

Commit

Permalink
Code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
craigmayhew committed Feb 11, 2024
1 parent 1e1f79e commit 454cb57
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/pages/cruncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,24 @@ mod numerics_to_text {
}

pub fn den_to_babylonian(str_num: &str) -> String {
let mut glyphs: Vec<String> = Vec::with_capacity(60);
let units = vec!["", "𒁹", "𒈫", "𒐈", "𒐉", "𒐊", "𒐋", "𒐌", "𒐍", "𒐎"];
let tens = vec!["", "𒌋", "𒎙", "𒌍", "𒐏", "𒐐", "𒐑"];

let mut glyphs: Vec<String> = Vec::with_capacity(60);
glyphs.push(" &nbsp; &nbsp; ".to_owned());
for i in 1..59 {
glyphs.push(format!("{}{}", tens[i / 10], units[i % 10]));
}
let mut val: Vec<&str> = vec![""; 1000];
let mut val: Vec<&str> = Vec::with_capacity(1);
let mut num: BigUint = num_bigint::BigUint::from_str_radix(&str_num, 10).unwrap();
let sixty: BigUint = 60.to_biguint().unwrap();
while num > Zero::zero() {
val.push(&glyphs[(&num % &sixty).to_usize().unwrap()]);
val.push(" &nbsp; ");
num /= &sixty;
}
//reverse the vector
val = val.iter().rev().cloned().collect();
//convert to String
val.into_iter().collect()
//reverse the vector and collect to String
val.iter().rev().cloned().collect()
}

pub fn dec_to_base(str_num: &str, base: u32) -> String {
Expand Down

0 comments on commit 454cb57

Please sign in to comment.