Skip to content

Commit

Permalink
Add the dobble example
Browse files Browse the repository at this point in the history
  • Loading branch information
krtab committed Mar 13, 2024
1 parent d3650d2 commit 132cdd5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions example/c/dobble.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// An encoding representing the problem of finding a suitable
// set of cards for https://en.wikipedia.org/wiki/Dobble.
// Cards are encoded on integers, with each position
// representing one of N_CARDS possible symbols.
#include <owi.h>
#include <stdlib.h>

// Number of symbols per card
#define CARD_SIZE 3

#define N_CARDS ((CARD_SIZE*CARD_SIZE) - CARD_SIZE + 1)

int popcount(unsigned int x) {
int count = 0;
for (int i = 0; i < N_CARDS; i++) {
count += x & 1;
x >>= 1;
}
return count;
}

int main() {
unsigned int cards[N_CARDS];
for (int i=0;i < N_CARDS; i++) {
unsigned int x = owi_i32();
owi_assume((x >> N_CARDS) == 0);
owi_assume(popcount(x) == CARD_SIZE);
cards[i] = x;
if (i > 0) {
owi_assume(cards[i] > cards[i-1]);
}
}
unsigned int acc = 1;
for (int i=0;i < N_CARDS; i++) {
for(int j=i+1; j < N_CARDS;j++) {
owi_assume(cards[i] != cards[j]);
unsigned int z = cards[i] & cards[j];
acc = acc & (z != 0);
acc = acc & ((z & (z-1)) == 0);
}
}
owi_assert(!acc);
}
1 change: 1 addition & 0 deletions example/c/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
%{bin:owi}
(file poly.c)
(file poly2.c)
(file dobble.c)
(package owi))
(files README.md))

0 comments on commit 132cdd5

Please sign in to comment.