Codewars: Rust workspace for solving the 'Ones and Zeros' kata
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
517 B

3 years ago
  1. ## Ones and Zeros
  2. Given an array of ones and zeroes, convert the equivalent binary value to an integer.
  3. >Eg: `[0, 0, 0, 1]` is treated as `0001` which is the binary representation of `1`.
  4. **Examples:**
  5. ```rust
  6. Testing: [0, 0, 0, 1] ==> 1
  7. Testing: [0, 0, 1, 0] ==> 2
  8. Testing: [0, 1, 0, 1] ==> 5
  9. Testing: [1, 0, 0, 1] ==> 9
  10. Testing: [0, 0, 1, 0] ==> 2
  11. Testing: [0, 1, 1, 0] ==> 6
  12. Testing: [1, 1, 1, 1] ==> 15
  13. Testing: [1, 0, 1, 1] ==> 11
  14. ```
  15. >*However, the arrays can have varying lengths, not just limited to 4.*