| about | help | code help+videos | done | prefs |
oddHalfs
Given an integer value, keep dividing it in half until the result 1. Count how many times the result of dividing the number is an odd number. For example: 16 itself is not odd, so it isn't counted! 16 / 2 = 8, an even number, so we don't count it, but keep going... 8 / 2 = 4, an even number, so we don't count it, but keep going... 4 / 2 = 2, an even number, so we don't count it, but keep going... 2 / 2 = 1, although 1 is odd, we don't count it because this is our base case... There were no odd values found along the way so we return 0! But: 11 is odd, so it is counted! 11 / 2 = 5, an odd number, so we count another 1 and keep going... 5 / 2 = 2, and even number, so we don't count it, but keep going... 2 / 2 = 1, Even though 1 is odd, we don't count it because this is our base case... There were two odd values found along the way so we return 2!oddHalfs(30) → 3 oddHalfs(31) → 4 oddHalfs(32) → 0 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 200 Post-solution available
Copyright Nick Parlante 2017 - privacy