34
|
1 /*
|
|
2 * Nov 10, 2009
|
|
3 * created by gongo.
|
|
4 *
|
|
5 * Nov 10, 2009
|
|
6 * modified by kent.
|
|
7 */
|
|
8
|
|
9 #include <stdio.h>
|
|
10 #include <stdlib.h>
|
|
11
|
|
12 (*ret)(int, void*);
|
|
13 void *env;
|
|
14
|
|
15
|
|
16 __code
|
|
17 print(int *numbers)
|
|
18 {
|
|
19 printf("%d-%d-%d-%d-%d-%d\n", numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]);
|
|
20 free(numbers);
|
|
21 goto ret(0, env);
|
|
22 }
|
|
23
|
|
24 __code
|
|
25 take(int *array, int size, int length)
|
|
26 {
|
|
27 int *taked = (int*)malloc(sizeof(int)*length);
|
|
28
|
|
29 memcpy(taked, array, sizeof(int)*length);
|
|
30 free(array);
|
|
31
|
|
32 goto print(taked);
|
|
33 }
|
|
34
|
|
35 __code
|
|
36 shuffle(int *array, int size, int idx)
|
|
37 {
|
|
38 int j = random() % size;
|
|
39 int tmp = array[idx];
|
|
40 array[idx] = array[j];
|
|
41 array[j] = tmp;
|
|
42
|
|
43 if (++idx < size) {
|
|
44 goto shuffle(array, size, idx);
|
|
45 } else {
|
|
46 goto take(array, size, 6);
|
|
47 }
|
|
48 }
|
|
49
|
|
50 __code
|
|
51 range_loop(int *array, int idx, int from, int to, int step, int size)
|
|
52 {
|
|
53 array[idx] = from;
|
|
54
|
|
55 if (from+step > to) {
|
|
56 goto shuffle(array, size, 0);
|
|
57 } else {
|
|
58 goto range_loop(array, idx+1, from+step, to, step, size);
|
|
59 }
|
|
60 }
|
|
61
|
|
62 __code
|
|
63 range(int from, int to, int step)
|
|
64 {
|
|
65 int size = (to-from+1)/step;
|
|
66 int *array = (int*)malloc(sizeof(int)*size);
|
|
67
|
|
68 goto range_loop(array, 0, from, to, step, size);
|
|
69 }
|
|
70
|
|
71 int
|
|
72 main()
|
|
73 {
|
|
74 srand(time(NULL));
|
|
75 ret = _CbC_return;
|
|
76 env = _CbC_environment;
|
|
77
|
|
78 goto range(1, 43, 1);
|
|
79 }
|
|
80
|