Skip to content

Commit 0a68737

Browse files
committed
EPI: parity
1 parent 8267d15 commit 0a68737

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

elements-of-programming-interviews/cpp/parity.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#include "test_framework/generic_test.h"
22
short Parity(unsigned long long x) {
3-
// TODO - you fill in here.
4-
return 0;
3+
bool parity = false;
4+
int shifts = 0;
5+
while (x) {
6+
parity = (x & 1 ? !parity : parity);
7+
x >>= 1;
8+
}
9+
return parity ? 1 : 0;
510
}
611

712
int main(int argc, char* argv[]) {

elements-of-programming-interviews/problem_mapping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ problem_mapping = {
1616
},
1717
"4.01 Computing the parity of a word": {
1818
"C++: parity.cc": {
19-
"passed": 0,
19+
"passed": 10000,
2020
"total": 10000
2121
},
2222
"Java: Parity.java": {

0 commit comments

Comments
 (0)