Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/helpers/print_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,23 @@ pub fn print_book(sdk: &SDKClient, book: &Ladder) {
}

pub fn get_precision(mut target: u64) -> usize {
let is_prime = |x| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems overly complicated. why not just divide by 2 until it's no longer divisible by 2, and divide by 5 until it's no longer divisible by 5?

let mut i = 2;
while i * i <= x {
if x % i == 0 {
return false;
}
i += 1;
}
true
};
let mut prime_factors = BTreeMap::new();
let mut candidate = 2;
while target > 1 {
if !is_prime(candidate) {
candidate += 1;
continue;
}
if target % candidate == 0 {
*prime_factors.entry(candidate).or_insert(0) += 1;
target /= candidate;
Expand Down