Programming question: Given a number, eg. 8, try to calculate and output a list/array of
that...
![subject](/tpl/images/cats/informatica.png)
Computers and Technology, 30.05.2020 02:01 mustafakhalil02
Programming question: Given a number, eg. 8, try to calculate and output a list/array of
that in each number's binary form - how many '1' in each number? (should not use string. count('1') in the Python. Efficiency is most important!)
Example: number is 8.
Expected output is - [0, 1, 1, 2, 1, 2, 2, 3, 1]
See some good code snippet (listed below), but not quite understand it? Can you help explain?
```code:
from typing import List
def countBits(num: int) -> List[int]:
""" count all numbers: from 0 to num (eg. 8)
-each number's binary bit in '1':
>>> countBits(8)
[0, 1, 1, 2, 1, 2, 2, 3, 1]
"""
res = [0]
while len(res) <= num:
for i in res[:num+1 - len(res)]: # :8 - 7- 6 -5 1
res += [i + 1]
return res
![ansver](/tpl/images/cats/User.png)
Answers: 3
Another question on Computers and Technology
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 21.06.2019 20:20
Sometimes writers elaborate on the truth when recalling past events so they can enhance their narrative essay with more interesting descriptions. do you feel that published writers should or should not embellish real life events just to make their stories more interesting?
Answers: 2
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 02:10
3. (5 points) describe what would be printed by the code below or what error would occur. const char* cstr = "0123456"; const char* ptr = & cstr[4]; cout < < ptr[-1] < < ptr < < endl; 1 4. (5 points) theseus has been trapped in a maze with a minotaur, which is trying to capture him. each round, theseus and the minotaur move through the maze; theseus towards the exit, and the minotaur towards theseus. theseus can move in any of the four cardinal directions, or he can wait for a round to see how the minotaur moves. write code that creates a data type to represent the possible moves that theseus could make.
Answers: 3
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 02:30
Experimental data that is expressed using numbers is said to be
Answers: 1
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 22:30
How many points do i need before i can send a chat
Answers: 1
You know the right answer?
Questions
![question](/tpl/images/cats/himiya.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/himiya.png)
![question](/tpl/images/cats/istoriya.png)
History, 01.08.2019 06:30
![question](/tpl/images/cats/istoriya.png)
History, 01.08.2019 06:30
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 01.08.2019 06:30
![question](/tpl/images/cats/biologiya.png)
![question](/tpl/images/cats/biologiya.png)
Biology, 01.08.2019 06:30
![question](/tpl/images/cats/en.png)
![question](/tpl/images/cats/biologiya.png)
Biology, 01.08.2019 06:30
![question](/tpl/images/cats/mkx.png)
![question](/tpl/images/cats/fr.png)
French, 01.08.2019 06:30
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 01.08.2019 06:30
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 01.08.2019 06:30
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 01.08.2019 06:30
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 01.08.2019 06:30
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 01.08.2019 06:30
![question](/tpl/images/cats/istoriya.png)
History, 01.08.2019 06:30
![question](/tpl/images/cats/mkx.png)
Arts, 01.08.2019 06:30
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 01.08.2019 06:30