Mercurial > hg > CbC > CbC_gcc
view CbC-examples/loto6.c @ 103:edcadcec937d
modify __rectype
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 23 Mar 2012 17:11:33 +0900 |
parents | 5f3bba7b355c |
children | 5d30d517ebed |
line wrap: on
line source
/* * Nov 10, 2009 * created by gongo. * * Nov 10, 2009 * modified by kent. */ #include <stdio.h> #include <stdlib.h> (*ret)(int, void*); void *env; __code print(int *numbers) { printf("%d-%d-%d-%d-%d-%d\n", numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]); free(numbers); goto ret(0, env); } __code take(int *array, int size, int length) { int *taked = (int*)malloc(sizeof(int)*length); memcpy(taked, array, sizeof(int)*length); free(array); goto print(taked); } __code shuffle(int *array, int size, int idx) { int j = random() % size; int tmp = array[idx]; array[idx] = array[j]; array[j] = tmp; if (++idx < size) { goto shuffle(array, size, idx); } else { goto take(array, size, 6); } } __code range_loop(int *array, int idx, int from, int to, int step, int size) { array[idx] = from; if (from+step > to) { goto shuffle(array, size, 0); } else { goto range_loop(array, idx+1, from+step, to, step, size); } } __code range(int from, int to, int step) { int size = (to-from+1)/step; int *array = (int*)malloc(sizeof(int)*size); goto range_loop(array, 0, from, to, step, size); } int main() { srand(time(NULL)); ret = _CbC_return; env = _CbC_environment; goto range(1, 43, 1); }