challenge ビンゴの結果を整形表示

重複無し乱数」の続編です。

「重複無し乱数」で作ったbingo関数の結果を下のように「何番目の乱数か」とセットにして10個ずつ折り返して表示するコードを書いてください。

>>> bingo(30)
  1  2  3  4  5  6  7  8  9 10
 29 14 16 13 30 15 22 11 25  9

 11 12 13 14 15 16 17 18 19 20
 23  4 18  5 28 17  8 12 21 20

 21 22 23 24 25 26 27 28 29 30
 26  6  2 19  1  7 10 27  3 24

>>> bingo(35)
  1  2  3  4  5  6  7  8  9 10
  7 15  3 32  1 16 17 28  6 29

 11 12 13 14 15 16 17 18 19 20
 19 23 30 26 20  5 12  2 25 31

 21 22 23 24 25 26 27 28 29 30
 35 13 24 18 11  8 10 34 22 21

 31 32 33 34 35
  9  4 27 33 14

Posted feedbacks - 秀丸マクロ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
    call srand tickcount;
    call bingo 35;
    endmacro;

bingo:
    ##i = 0;
    while( ##i < ##1 ) {
        ##dest[##i] = ##i + 1;
        ##i = ##i + 1;
    }
    ##i = 0;
    while( ##i < ##1 ) {
        call rand;
        ##r = ##return % ( ##1 - ##i ) + ##i;
        ##tmp = ##dest[##r];
        ##dest[##r] = ##dest[##i];
        ##dest[##i] = ##tmp;
        ##i = ##i + 1;
    }
    ##keta = strlen( str( ##1 ) );
    ##i = 0;
    while( ##i < ##1 ) {
        ##next = ##i + 10;
        if ( ##next > ##1 ) {
            ##next = ##1;
        }
        ##ii = ##i;
        while( ##ii < ##next ) {
            if ( ##ii > ##i ) {
                insert " ";
            }
            call KetaSoroe ##ii+1, ##keta;
            insert $$return;
            ##ii = ##ii + 1;
        }
        insert "\n";
        ##ii = ##i;
        while( ##ii < ##next ) {
            if ( ##ii > ##i ) {
                insert " ";
            }
            call KetaSoroe ##dest[##ii], ##keta;
            insert $$return;
            ##ii = ##ii + 1;
        }
        insert "\n\n";
        ##i = ##next;
    }
    return;

KetaSoroe:
    ##i = ##2 - strlen( str( ##1 ) );
    $$result = "";
    if ( ##i >= 0 ) {
        while( ##i > 0 ) {
            $$result = $$result + " ";
            ##i = ##i - 1;
        }
    }
    $$result = $$result + str( ##1 );
    return $$result;

rand:
    #rand_x = #rand_x * 214013 + 2531011;
    if ( #rand_x < 0 ) {
        return ( ( #rand_x + 1 ) / 65536 - 1 ) & 32767;
    }
    return #rand_x / 65536 & 32767;

srand:
    #rand_x = ##1;
    return;

Index

Feed

Other

Link

Pathtraq

loading...