Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
68
Task/Loops-Nested/Dc/loops-nested.dc
Normal file
68
Task/Loops-Nested/Dc/loops-nested.dc
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
1 ss [Seed of the random number generator.]sz
|
||||
|
||||
[*
|
||||
* lrx -- (number)
|
||||
* Push a random number from 1 to 20.
|
||||
*]sz
|
||||
[
|
||||
[ [If preventing modulo bias:]sz
|
||||
sz [Drop this random number.]sz
|
||||
lLx [Loop.]sz
|
||||
]SI
|
||||
[ [Loop:]sz
|
||||
[*
|
||||
* Formula (from POSIX) for random numbers of low quality.
|
||||
* Push a random number from 0 to 32767.
|
||||
*]sz
|
||||
ls 1103515245 * 12345 + 4294967296 % ss
|
||||
ls 65536 / 32768 %
|
||||
|
||||
d 32768 20 % >I [Prevent modulo bias.]sz
|
||||
]d SL x
|
||||
20 % 1 + [Be from 1 to 20.]sz
|
||||
LLsz LIsz [Restore L, I.]sz
|
||||
]sr
|
||||
|
||||
|
||||
5 sb [b = Total rows]sz
|
||||
5 sc [c = Total columns]sz
|
||||
|
||||
[Fill array a[] with random numbers from 1 to 20.]sz
|
||||
[ [Inner loop for j:]sz
|
||||
lrx [Push random number.]sz
|
||||
li lc * lj + [Push index of a[i, j].]sz
|
||||
:a [Put in a[].]sz
|
||||
lj 1 + d sj [j += 1]sz
|
||||
lc >I [Loop while c > j.]sz
|
||||
]sI
|
||||
[ [Outer loop for i:]sz
|
||||
0 d sj [j = 0]sz
|
||||
lc >I [Enter inner loop.]sz
|
||||
li 1 + d si [i += 1]sz
|
||||
lb >L [Loop while b > i.]sz
|
||||
]sL
|
||||
0 d si [i = 0]sz
|
||||
lb >L [Enter outer loop.]sz
|
||||
|
||||
[Find a 20.]sz
|
||||
[ [If detecting a 20:]sz
|
||||
li lj + 3 + Q [Break outer loop.]sz
|
||||
]sD
|
||||
[ [Inner loop for j:]sz
|
||||
li lc * lj + [Push index of a[i,j].]sz
|
||||
;a [Push value from a[].]sz
|
||||
p [Print value and a newline.]sz
|
||||
20 =D [Detect a 20.]sz
|
||||
lj 1 + d sj [j += 1]sz
|
||||
lc >I [Loop while c > j.]sz
|
||||
]sI
|
||||
[ [Outer loop for i:]sz
|
||||
0 d sj [j = 0]sz
|
||||
lc >I [Enter inner loop.]sz
|
||||
[==
|
||||
]P [Print "==" and a newline.]sz
|
||||
li 1 + d si [i += 1]sz
|
||||
lb >L [Loop while b > i.]sz
|
||||
]sL
|
||||
0 d si [i = 0]sz
|
||||
lb >L [Enter outer loop.]sz
|
||||
Loading…
Add table
Add a link
Reference in a new issue