Given an array of one's and zero's convert the equivalent binary value to an integer.
Eg: [0, 0, 0, 1] is treated as 0001 which is the binary representation of 1.
Examples:
Testing: [0, 0, 0, 1] ==> 1
Testing: [0, 0, 1, 0] ==> 2
Testing: [0, 1, 0, 1] ==> 5
Testing: [1, 0, 0, 1] ==> 9
Testing: [0, 0, 1, 0] ==> 2
Testing: [0, 1, 1, 0] ==> 6
Testing: [1, 1, 1, 1] ==> 15
Testing: [1, 0, 1, 1] ==> 11
However, the arrays can have varying lengths, not just limited to 4.
'매일매일개발 > Codewars' 카테고리의 다른 글
codewars #78 Convert PascalCase string into snake_case (5kyu) (0) | 2018.07.12 |
---|---|
codewars #77 Tortoise racing (6kyu) (0) | 2018.07.11 |
codewars #75 Numericals of a String (6kyu) (0) | 2018.07.09 |
codewars #74 CamelCase to underscore(6kyu) (0) | 2018.07.06 |
codewars #73 Counting Duplicates (6kyu) (0) | 2018.07.05 |