-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkSuperMajority.ts
48 lines (46 loc) · 1.49 KB
/
checkSuperMajority.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Check for a Supermajority.
//
// Write a circuit which checks whether 2/3 or more ballots approved the motion (supermajority).
// Each ballot is a number, with 0 meaning 'no' and any other number meaning 'yes'.
// The circuit should return 1 to indicate the motion passes and 0 to indicate it fails.
//
// For example:
// //! test [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] => [0]
// //! test [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] => [1]
// //! test [0, 7, 8, 0, 1, 1, 0, 0, 2, 2] => [0]
// //! test [0, 7, 8, 0, 1, 1, 0, 3, 2, 2] => [1]
//
// The format above is also used to check circuits with `cargo test`. Simply move them to their own
// line, similar to test annotations in `loopAdd.ts` and `greaterThan10.ts`.
export default function main(
// The main function has this quirky signature to tell Summon to instantiate it for exactly 10
// inputs. However we can implement the general algorithm by writing `impl` which simply takes an
// array of inputs with unspecified length.
ballot0: number,
ballot1: number,
ballot2: number,
ballot3: number,
ballot4: number,
ballot5: number,
ballot6: number,
ballot7: number,
ballot8: number,
ballot9: number,
) {
return impl([
ballot0,
ballot1,
ballot2,
ballot3,
ballot4,
ballot5,
ballot6,
ballot7,
ballot8,
ballot9,
]);
}
function impl(ballots: number[]) {
// TODO: Return true iff 2/3 or more ballots are non-zero. (In the resulting circuit, true will
// be converted to 1 and false will be converted to 0.)
}