Created
November 8, 2009 14:15
-
-
Save gongo/229291 to your computer and use it in GitHub Desktop.
ロト6の番号をランダムに生成する (via http://gist.github.com/226929)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
(*ret)(int); | |
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 = return; | |
env = environment; | |
goto range(1, 43, 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun range (count &optional from step) | |
(let ((from (or from 0)) | |
(step (or step 1)) | |
(result nil)) | |
(while (> count 0) | |
(setq result (cons from result)) | |
(incf from) | |
(decf count)) | |
(vconcat (nreverse result)))) | |
(defun loto6 () | |
"Return loto6 number that is generated at random" | |
(let ((array (nthcdr 37 (append (shuffle-vector (range 43 1)) nil)))) | |
(mapconcat '(lambda (i) (number-to-string i)) array "-" | |
))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment