1
0
Fork 0
mirror of synced 2025-09-23 04:08:33 +00:00
ZoKrates/zokrates_cli/examples
Ahmed Castro f84faaae83
Sudoku example fix
**Problem**

the logic behind `countDuplicates` is invalid because it's doing this:
(incorrect)
```
if(duplicates + e11 == e21)
  duplicates = 1;
else
  duplicates = 0;
```

Instead of this:
(correct)
```
if(e11 == e21)
  duplicates = duplicates + 1;
else
  duplicates = duplicates;
```

**Solution**

I'm using an auxiliary variable to fix this

**Alternative solution**

We can also fix it with an array and a loop. But I went for the auxiliary variable for no particular reason.

```
def countDuplicates(field e11, field e12, field e21, field e22) -> u32 {
    u32[6] mut duplicates = [0,0,0,0,0,0];
    duplicates[0] = e11 == e12 ? 1 : 0;
    duplicates[1] = e11 == e21 ? 1 : 0;
    duplicates[2] = e11 == e22 ? 1 : 0;
    duplicates[3] = e12 == e21 ? 1 : 0;
    duplicates[4] = e12 == e22 ? 1 : 0;
    duplicates[5] = e21 == e22 ? 1 : 0;

    u32 mut count = 0;
    for u32 i in 0..5 {
        count = count + duplicates[i];
    }

    return count;
}
```

And btw, I also added an assert to make sure we check for this validation. I've tested this on the playground and on chain on goerli and with this changes it works correctly.
2023-03-18 20:09:28 -06:00
..
alias deprecate multi returns 2022-06-21 15:03:53 +02:00
arrays merge staging 2022-06-28 19:23:45 +02:00
book update book, merge develop and merge conflicts 2023-01-30 15:27:17 +01:00
compile_errors validate expressions, add more tests 2022-12-01 21:07:42 +01:00
functions merge staging 2022-06-28 19:23:45 +02:00
imports change syntax in cli/examples 2022-04-06 20:23:58 +02:00
merkleTree merge staging 2022-06-28 19:23:45 +02:00
runtime_errors extract panics just before flattening, simplify zir, remove redundant checks in code generation 2022-08-16 18:53:21 +02:00
structs merge staging 2022-06-28 19:23:45 +02:00
sudoku Sudoku example fix 2023-03-18 20:09:28 -06:00
tuples merge staging 2022-06-28 19:23:45 +02:00
add.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
argument_reassign.zok merge staging 2022-06-28 19:23:45 +02:00
array_generic_inference.zok spaces > tabs 2022-06-01 00:04:40 +02:00
array_overload.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
assign_to_element.zok merge staging 2022-06-28 19:23:45 +02:00
bool_and.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
bool_not.zok spaces > tabs 2022-06-01 00:04:40 +02:00
bool_or.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
boolean_literal.zok spaces > tabs 2022-06-01 00:04:40 +02:00
brackets.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
call_in_const.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
call_in_const_aux.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
call_in_constant.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
comments.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
comparison_operators.zok merge staging 2022-06-28 19:23:45 +02:00
complex_call_in_constant.zok merge staging 2022-06-28 19:23:45 +02:00
conditions.zok spaces > tabs 2022-06-01 00:04:40 +02:00
constant_in_sig.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
constant_index_on_spread_inline.zok spaces > tabs 2022-06-01 00:04:40 +02:00
decimal_literal.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
empty_spread_propagation.zok merge staging 2022-06-28 19:23:45 +02:00
explicit_generic.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
factorization.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
flatten.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
for.zok merge staging 2022-06-28 19:23:45 +02:00
functions_equivalent.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
left_side_call.zok spaces > tabs 2022-06-01 00:04:40 +02:00
multiple_witnesses.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
n_choose_k.zok revert example change, fmt tweaks 2022-08-19 17:23:49 +02:00
no_flatten.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
pow.zok merge staging 2022-06-28 19:23:45 +02:00
pragma.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
propagate.zok merge staging 2022-06-28 19:23:45 +02:00
propagate_call.zok deprecate multi returns 2022-06-21 15:03:53 +02:00
reassignment.zok merge staging 2022-06-28 19:23:45 +02:00
reduceable_exponent.zok spaces > tabs 2022-06-01 00:04:40 +02:00
shadowing.zok implement shadowing only at the semantic phase 2022-07-21 17:52:54 +02:00
simple_add.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
simple_conditional.zok fix tests 2022-05-11 21:33:57 +02:00
simple_mul.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
spaces_tabs_comments.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
struct_generic_inference.zok spaces > tabs 2022-06-01 00:04:40 +02:00
sub.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
synonyms.zok spaces > tabs 2022-06-01 00:04:40 +02:00
taxation.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
ternary_eq.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
test1.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
test_lt_max_value.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
waldo.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00
wavelets.zok change syntax in cli/examples 2022-04-06 20:23:58 +02:00