Skip to content

Instantly share code, notes, and snippets.

@xtotdam
Created October 4, 2017 17:26
Show Gist options
  • Select an option

  • Save xtotdam/77d2c34188583dd4094b64443cd5f55e to your computer and use it in GitHub Desktop.

Select an option

Save xtotdam/77d2c34188583dd4094b64443cd5f55e to your computer and use it in GitHub Desktop.
// counting lengths of chains
int *lengths = (int *)calloc(N, sizeof(int));
int *zeros = (int *)calloc(N, sizeof(int));
int len, j;
for (i = 0; i < N; i++)
{
if (atoms[i] == 0)
{
zeros[cnt] = i;
cnt++;
}
}
for (i = 0; i < cnt; i++)
{
if (i < cnt - 1)
{
len = zeros[i + 1] - zeros[i] - 1;
for (j = zeros[i] + 1; j < zeros[i + 1]; j++)
{
lengths[j] = len;
}
}
else
{
len = N + zeros[0] - zeros[cnt - 1] - 1;
for (j = 0; j < zeros[0]; j++)
{
lengths[j] = len;
}
for (j = zeros[cnt - 1] + 1; j < N; j++)
{
lengths[j] = len;
}
}
}
free(lengths);
free(zeros);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment