Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sudoku example fix #1287

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions zokrates_cli/examples/sudoku/sudoku_checker.zok
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@
// We use a naive encoding of the values as `[1, 2, 3, 4]` and rely on if-else statements to detect duplicates

def countDuplicates(field e11, field e12, field e21, field e22) -> field {
field mut duplicates = e11 == e12 ? 1 : 0;
duplicates = duplicates + e11 == e21 ? 1 : 0;
duplicates = duplicates + e11 == e22 ? 1 : 0;
duplicates = duplicates + e12 == e21 ? 1 : 0;
duplicates = duplicates + e12 == e22 ? 1 : 0;
duplicates = duplicates + e21 == e22 ? 1 : 0;
return duplicates;
field mut duplicates = 0;
field mut duplicatesAux = e11 == e12 ? 1 : 0;
duplicates = duplicates + duplicatesAux;
duplicatesAux = e11 == e21 ? 1 : 0;
duplicates = duplicates + duplicatesAux;
duplicatesAux = e11 == e22 ? 1 : 0;
duplicates = duplicates + duplicatesAux;
duplicatesAux = e12 == e21 ? 1 : 0;
duplicates = duplicates + duplicatesAux;
duplicatesAux = e12 == e22 ? 1 : 0;
duplicates = duplicates + duplicatesAux;
duplicatesAux = e21 == e22 ? 1 : 0;

return countDuplicates;
}

// returns 0 for x in (1..4)
Expand Down Expand Up @@ -74,5 +81,6 @@ def main(field a21, field b11, field b22, field c11, field c22, field d21, priva
duplicates = duplicates + countDuplicates(b12, b22, d12, d22);

// the solution is correct if and only if there are no duplicates
assert(duplicates == 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine but then let's return nothing

return duplicates == 0;
}