Skip to content

Instantly share code, notes, and snippets.

@brtzsnr
Created February 14, 2011 12:16
Show Gist options
  • Save brtzsnr/825795 to your computer and use it in GitHub Desktop.
Save brtzsnr/825795 to your computer and use it in GitHub Desktop.
int32_t Topswops::Evaluate() {
int8_t *temp = (int8_t *)malloc(size);
memcpy(temp, wops, size);
score = 0;
while (temp[0] != 1) {
score++;
Rotate(temp, 0, temp[0]);
}
free(temp);
return score;
}
void Rotate(int8_t *buff, int start, int end) {
buff += start;
int length = end - start;
for (int i = 0, j = length - 1; i < length / 2; i += 2, j -= 2) {
int8_t swp0 = buff[i + 0];
int8_t swp1 = buff[i + 1];
buff[i + 0] = buff[j - 0];
buff[i + 1] = buff[j - 1];
buff[j + 0] = swp0;
buff[j - 1] = swp1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment