Skip to content

Commit

Permalink
67: Submit
Browse files Browse the repository at this point in the history
  • Loading branch information
sankichi92 committed Dec 31, 2023
1 parent 59e6bf4 commit 7bb9204
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions 67-counting-bits/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
pub fn count_bits(n: i32) -> Vec<i32> {
(0..=n)
.map(|i| format!("{i:b}").chars().filter(|&c| c == '1').count() as i32)
.collect()
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
fn case1() {
assert_eq!(count_bits(2), vec![0, 1, 1]);
}

#[test]
fn case2() {
assert_eq!(count_bits(5), vec![0, 1, 1, 2, 1, 2]);
}
}

0 comments on commit 7bb9204

Please sign in to comment.