Skip to content

Instantly share code, notes, and snippets.

@bagder
Last active October 26, 2016 21:28
Show Gist options
  • Save bagder/382e59f24217dcf77e20389a4a7c8aeb to your computer and use it in GitHub Desktop.
Save bagder/382e59f24217dcf77e20389a4a7c8aeb to your computer and use it in GitHub Desktop.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define INPUT "Rgn02.txt"
#define WIDTH 8 /* 6 bytes + CRLF */
unsigned char there[(2<<15)*16*16*2];
static inline int num(unsigned char *reg)
{
register unsigned int val =
(reg[0]&31) |
((reg[1]&31)<<5) |
((reg[2]&31)<<10) |
((reg[3]&15)<<15) |
((reg[4]&15)<<19) |
((reg[5]&15)<<23);
return there[(unsigned int)val>>3] ^= (1<< (val & 7));
}
int main(void)
{
struct stat st;
if(!stat(INPUT, &st)) {
off_t size = st.st_size;
char *data = malloc(size+1);
FILE *f = fopen(INPUT, "rb");
if(f) {
if(size == fread(data, 1, size, f)) {
int fields = size/WIDTH;
int i;
for(i=0; i<fields; i++) {
if(!num(&data[i*WIDTH])) {
printf("%u\n", i);
}
}
}
fclose(f);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment