Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Jan 7, 2025
1 parent 1f86872 commit 8d38402
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions rust/eliuds-eggs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
pub fn egg_count(decimal: u32) -> usize {
let binary = decimal_to_binary(decimal);
let eggs = count('1', binary);
eggs
count('1', binary)
}

fn decimal_to_binary(decimal: u32) -> String {
let mut result = "".to_string();

let mut n = decimal;
while n != 0 {
let remainder = n % 2;
n = n / 2;
let c = char::from_digit(remainder, 10).unwrap();
result.insert(0, c);
result.insert(0, char::from_digit(remainder, 10).unwrap());
}

result
}

Expand Down

0 comments on commit 8d38402

Please sign in to comment.