First class environments: Difference between revisions

(Added PicoLisp)
Line 9:
 
When all hailstone values dropped to 1, processing stops, and the total number of hailstone steps for each environment is printed.
 
=={{header|C}}==
Well, this fits the semantics, not sure about the spirit&mdash;<lang C>#include <stdio.h>
 
#define JOBS 12
#define jobs(a) switch_to(0); for (a = 0; a < JOBS; switch_to(++a))
typedef struct { int seq, cnt; } env_t;
 
env_t env[JOBS] = {{0, 0}};
int *seq, *cnt;
 
void hail()
{
printf("% 4d", *seq);
if (*seq != 1) (*cnt)++;
else return;
 
if ((*seq & 1)) *seq = 3 * *seq + 1;
else *seq /= 2;
}
 
void switch_to(int id)
{
seq = &env[id].seq;
cnt = &env[id].cnt;
}
 
int main()
{
int i, done = 0;
jobs(i) { env[i].seq = i + 1; }
 
while (!done) {
jobs(i) hail();
printf("\n");
 
done = 1;
jobs(i) if (*seq != 1) done = 0;
}
 
printf("COUNTS:\n");
jobs(i) printf("% 4d", *cnt);
printf("\n");
 
return 0;
}</lang>output<lang> 1 2 3 4 5 6 7 8 9 10 11 12
1 1 10 2 16 3 22 4 28 5 34 6
1 1 5 1 8 10 11 2 14 16 17 3
1 1 16 1 4 5 34 1 7 8 52 10
1 1 8 1 2 16 17 1 22 4 26 5
1 1 4 1 1 8 52 1 11 2 13 16
1 1 2 1 1 4 26 1 34 1 40 8
1 1 1 1 1 2 13 1 17 1 20 4
1 1 1 1 1 1 40 1 52 1 10 2
1 1 1 1 1 1 20 1 26 1 5 1
1 1 1 1 1 1 10 1 13 1 16 1
1 1 1 1 1 1 5 1 40 1 8 1
1 1 1 1 1 1 16 1 20 1 4 1
1 1 1 1 1 1 8 1 10 1 2 1
1 1 1 1 1 1 4 1 5 1 1 1
1 1 1 1 1 1 2 1 16 1 1 1
1 1 1 1 1 1 1 1 8 1 1 1
1 1 1 1 1 1 1 1 4 1 1 1
1 1 1 1 1 1 1 1 2 1 1 1
COUNTS:
0 1 7 2 5 8 16 3 19 6 14 9</lang>
 
=={{header|PicoLisp}}==
Anonymous user