Skip to content

Latest commit

 

History

History

powers-of-2

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
  • Completed at: 2023-07-10T21:32:17.927Z

  • Completed languages: javascript

  • Tags: Mathematics, Fundamentals

  • Rank: 8 kyu

Description

Complete the function that takes a non-negative integer n as input, and returns a list of all the powers of 2 with the exponent ranging from 0 to n ( inclusive ).

Examples

n = 0  ==> [1]        # [2^0]
n = 1  ==> [1, 2]     # [2^0, 2^1]
n = 2  ==> [1, 2, 4]  # [2^0, 2^1, 2^2]
  n = String.fromCharCode(0)  ==> String.fromCharCode(1)
  n = String.fromCharCode(1)  ==> String.fromCharCode(1) + String.fromCharCode(2)
  n = String.fromCharCode(2)  ==> String.fromCharCode(1) + String.fromCharCode(2) + String.fromCharCode(4)
## Encodings

`purity: LetRec`  
`numEncoding: BinaryScott`  
export `foldr` for your `List` encoding
RISC-V: The function signature is:

```c
void powers_of_two(size_t n, uint64_t powers[n + 1]);
```

Write the result to `powers`. You may assume it is large enough to hold the result. You should not return anything.
- Since BF doesn't have arrays, you should output each element individually.
- Outputs will always fit within a byte