[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c
From: |
Ben Pfaff |
Subject: |
PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c |
Date: |
Wed, 04 Feb 2009 15:24:19 +0000 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20061205 Iceweasel/2.0.0.1 (Debian-2.0.0.1+dfsg-1) |
Follow-up Comment #7, bug #25466 (project pspp):
Actually, here's a solution that is even better. A test program using it
calculates (correctly) and prints *all* the values for 1 <= N <= 30, 1 <= W <=
N*(N+1)/2, in under .2 seconds *total*.
The runtime of this algorithm is O(N*W) and it uses O(W) space.
int ranksum6(int N, int W)
{
int *array;
int max;
int total;
assert (N >= 0);
if (N == 0)
return 0;
else if (W <= 0)
return 1 << N;
else if (W > N * (N + 1) / 2)
return 0;
else if (N == 1)
return 1;
array = calloc (sizeof *array, W + 1);
array[W] = 1;
max = W;
total = 0;
for (; N > 1; N--)
{
int max_sum = N * (N + 1) / 2;
int i;
if (max_sum < max)
max = max_sum;
for (i = 1; i <= max; i++)
if (array[i] != 0)
{
int new_W = i - N;
if (new_W <= 0)
total += array[i] * (1 << (N - 1));
else
array[new_W] += array[i];
}
}
total += array[1];
free (array);
return total;
}
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?25466>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, Michel Boaventura, 2009/02/02
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, Michel Boaventura, 2009/02/02
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, Ben Pfaff, 2009/02/02
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, John Darrington, 2009/02/02
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, Ben Pfaff, 2009/02/03
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, John Darrington, 2009/02/03
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, John Darrington, 2009/02/03
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c,
Ben Pfaff <=
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, Ben Pfaff, 2009/02/04
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, John Darrington, 2009/02/05
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, Ben Pfaff, 2009/02/05
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, Ben Pfaff, 2009/02/05
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, John Darrington, 2009/02/05
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, Ben Pfaff, 2009/02/05
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, John Darrington, 2009/02/05
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, Ben Pfaff, 2009/02/06
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, John Darrington, 2009/02/06
- PSPP-BUG: [bug #25466] Compile problem on wilcoxon.c, Ben Pfaff, 2009/02/06