Skip to content

Commit

Permalink
Performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
iByteABit256 committed Feb 14, 2023
1 parent 7ff3fbb commit 5ce9bc8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "mrn-generator"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
authors = ["Pavlos Smith <paulsmith4561+at+gmail.com>"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ fn is_mrn_valid(mrn: &str) -> Option<char> {

let mrn_temp: String = mrn_iter.collect();

// Powers of 2
let multipliers: Vec<u32> = (0..mrn_temp.len()).map(|n| 1 << n).collect();

let multiplied_sum: u32 = mrn_temp.chars().zip(multipliers).map(|(c,m)| check_character_value(c) as u32 * m).sum();
// Multiply each char value with it's power of 2 and sum them
let multiplied_sum: u32 = mrn_temp.chars().zip(0..mrn_temp.len()).map(|(c,m)| (check_character_value(c) as u32) << m).sum();

let check_digit: u8 = (multiplied_sum % 11).try_into().unwrap();
check_remainder_value(check_digit, last_digit)
Expand Down

0 comments on commit 5ce9bc8

Please sign in to comment.