On Thu, Aug 5, 2010 at 5:09 PM, Raul Miller <[email protected]> wrote:
> On Thu, Aug 5, 2010 at 3:04 AM, Zsbán Ambrus <[email protected]> wrote:
>> gij=: a.i. 2{:: './gijl.so gij n i *c' 15!:0 ];$&'x'
>> gij 30
>
> This hangs for me, with no cpu being consumed.
Try this standalone C example first.
Also, could you tell me what system you are on, what C compiler you're
using, what exact compiler command line did you compile it with, what
J version you called it from, and any other useful information? In
case you want to debug it, it worked for me on an amd64 linux debian
etch system compiled with vanilla gcc 4.4.2 and both
j602/2008-03-03/16:45 and j701/beta/2010-03-31/11:40.
$ cat gij.c
#include <stdio.h>
#include <stdlib.h>
// OEIS A090822 Gijswijt's sequence
void
gij(int nm, char *a) {
for(int n = 0; n < nm; n++) {
int r = 1;
for (int l = 1; l <= n/2; l++) {
int s = 0;
int q = 0;
while (!q) {
s++;
if (l * (1+s) <= n)
for (int u = 1; !q && u <= l; u++)
q = a[n - l * (s - 1) - u] !=
a[n - l * s - u];
else
q = 1;
}
if (r < s)
r = s;
}
a[n] = r;
}
}
int
main(void) {
static const int l = 220;
char a[l];
gij(l, a);
for (int k = 0; k < l; k++)
printf("%d ", a[k]);
printf("\n");
return 0;
}
$ gcc -std=gnu99 -Wall -O -o gij gij.c
$ ./gij
1 1 2 1 1 2 2 2 3 1 1 2 1 1 2 2 2 3 2 1 1 2 1 1 2 2 2 3 1 1 2 1 1 2 2
2 3 2 2 2 3 2 2 2 3 3 2 1 1 2 1 1 2 2 2 3 1 1 2 1 1 2 2 2 3 2 1 1 2 1
1 2 2 2 3 1 1 2 1 1 2 2 2 3 2 2 2 3 2 2 2 3 3 2 2 2 3 2 1 1 2 1 1 2 2
2 3 1 1 2 1 1 2 2 2 3 2 1 1 2 1 1 2 2 2 3 1 1 2 1 1 2 2 2 3 2 2 2 3 2
2 2 3 3 2 1 1 2 1 1 2 2 2 3 1 1 2 1 1 2 2 2 3 2 1 1 2 1 1 2 2 2 3 1 1
2 1 1 2 2 2 3 2 2 2 3 2 2 2 3 3 2 2 2 3 2 2 2 3 2 2 2 3 3 2 2 2 3 2 2
2 3 2 2 2 3 3 3 3 4
$
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm