Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Last active May 7, 2021 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save md2perpe/dfeea26249dfefbebcdcb2b7c6145c00 to your computer and use it in GitHub Desktop.
Save md2perpe/dfeea26249dfefbebcdcb2b7c6145c00 to your computer and use it in GitHub Desktop.
#include <stdio.h>
typedef int square;
typedef int row;
typedef int col;
int is_valid_row(row n)
{
return (
n == 0b0011 ||
n == 0b0101 ||
n == 0b1001 ||
n == 0b0110 ||
n == 0b1010 ||
n == 0b1100
);
}
int is_valid_col(col n)
{
return (
n == 0x0011 ||
n == 0x0101 ||
n == 0x1001 ||
n == 0x0110 ||
n == 0x1010 ||
n == 0x1100
);
}
row get_row(square sq, int r)
{
return (sq & (0b0000000000001111<<(4*r))) >> 4*r;
}
col get_col(square sq, int c)
{
return ((sq & 0b0001000100010001<<c) >> c);
}
int is_valid_square(square sq)
{
return (
is_valid_row(get_row(sq, 0)) &&
is_valid_row(get_row(sq, 1)) &&
is_valid_row(get_row(sq, 2)) &&
is_valid_row(get_row(sq, 3)) &&
is_valid_col(get_col(sq, 0)) &&
is_valid_col(get_col(sq, 1)) &&
is_valid_col(get_col(sq, 2)) &&
is_valid_col(get_col(sq, 3))
);
}
int main() {
int counter = 0;
for (int i=0; i<0x10000; i++)
{
if (is_valid_square(i)) {
counter++;
}
}
printf("%d\n", counter);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment