Level 5Computational efficiencyWrite a program
Parity, under par
Read n. Output 1 if n has an odd number of 1 bits, otherwise 0. A correct program passes; a program at or under par shows you found the cheap path. Hint: you only ever need one bit of the count, and XOR with 1 flips a bit.
Public tests
- input 0 → 0
- input 1 → 1
- input 3 → 0
- input 7 → 1
- input 255 → 0
- input 128 → 1
Par: 1530 cycles in total over these tests. Skills: XOR, cost of branches.
New to this? Silicon Studio 11: Arithmetic logic unit
How results are computed: model assumptions.
One instruction per line. Labels end with a colon, comments start with a semicolon. Numbers can be 12, 0x0C or 0b1100.