Constrained random points on a circle: Difference between revisions

Simpler D version
(Simpler D version)
Line 427:
 
=={{header|D}}==
<lang d>import std.stdio, std.random, std.math, std.algorithm;
From the Python version.
<lang d>import std.stdio, std.random, std.math, std.algorithm;
 
void main() {
intchar[231][31] possibletable = ' ';
foreach (x; -15 .. 16)
foreach (y; -15 .. 16)
if (10 <= abs(x + y * 1i) && abs(x + y * 1i) <= 15)
possible ~= [x, y];
 
foreach (xi; -150 .. 16100) {
int[int[2]] world;
foreach (_; 0 .. 100)int x, y;
}do {
world[randomSample(possible, 1).front]++;
int[2] px = [xuniform(-15, y]16);
 
foreach (x; y = uniform(-15 .., 16) {;
} if while(10 <= abs(x12.5 + y * 1i) &&- abs(x + y * 1i)) <=> 152.5);
string line;
foreachtable[x (y;+ -15][y ..+ 16)15] {= '*';
int[2] p = [x, y];
line ~= (p in world) ? '0'+min(9, world.get(p, 0)) : ' ';
}
writeln(line);
}
 
foreach (yrow; -15 .. 16table)
writeln(linerow);
}</lang>
<pre>
1 11 *
1 * ** 1* 1
11 * * 1
1** 1* 1* 1 ** 1 12 * *
* * 1 1 2 2 ** *
1 ** 2 ** *
2 * 1 *
11 1*
* 1 11 ***
* * * 11 1 21 1
1 1 * * *
* 1 * 1
* possible ~= [x, y]; *
1** 2 2 1 * *
* 1 1 *
1 2 1 *
1 * </pre>
* 1 1 1 1 *
1 * 1
1 * **
111 * * *
* * * * 1
* 1 * ** 1
1 * * * * * *
2 1 ** * ** ** * 1
1 ** 11
* * * * 1 11
12 1 ** 11 </pre>
1 2 2 1
1 1 1 1
11 1 1 1
1211 1
1 2 1
1 1
1 </pre>
 
=={{header|F_Sharp|F#}}==
Anonymous user