1
0
Fork 0
mirror of synced 2025-09-23 04:08:33 +00:00
Commit graph

14 commits

Author SHA1 Message Date
Ahmed Castro
48885d64a4
Update sudoku_checker.zok 2023-03-24 16:37:58 -06:00
Ahmed Castro
30c9d8b8b1
Update sudoku_checker.zok 2023-03-24 16:36:49 -06:00
Ahmed Castro
2e551b3d16
Update sudoku_checker.zok 2023-03-21 11:53:10 -06:00
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
Ahmed Castro
60ee62d309
Fixed small typo
Found a small typo while testing this.
Cheers!
2023-03-16 19:01:46 -06:00
dark64
e75552b0eb merge staging 2022-06-28 19:23:45 +02:00
schaeff
241447a09c implement and update zok files 2022-06-13 20:17:40 +02:00
dark64
16f2b4c3ac change syntax in cli/examples 2022-04-06 20:23:58 +02:00
schaeff
eb492153f4 add docs, use alias in example 2021-10-12 12:10:02 +03:00
schaeff
304e4fa3cb wip 2020-09-16 17:57:12 +02:00
schaeff
58b3c00efe introduce simpler syntax for single return and empty return 2020-08-04 00:27:26 +02:00
schaeff
9f2fecf7ec update zok to new assert syntax, rewrite NotEq 2020-07-15 22:23:37 +02:00
schaeff
50be20e8ba complete changes 2020-07-13 17:05:59 +02:00
schaeff
5c1a361619 wip 2020-07-13 09:20:27 +02:00