Anonymous user
Percolation/Bond percolation: Difference between revisions
Fixed performance problem in the D entry.
(Removed unused variable mn from C entry.) |
(Fixed performance problem in the D entry.) |
||
Line 190:
void initialize(in double prob, ref Xorshift rng) {
static assert(rng.front.min == 0);
immutable thresh = cast(uint)(rng.front.max * prob);
bool randP() { // Performance optimization.
immutable result = rng.front < thresh;
rng.popFront;
return result;
}
cells[0 .. nc] = bottomWall | rightWall; // First row.
Line 195 ⟶ 203:
foreach (immutable r; 1 .. nr + 1) {
foreach (immutable c; 1 .. nc)
cells[pos++] = (randP ? bottomWall : empty) |
cells[pos++] = rightWall | (randP
}
Line 311:
p = 0.80: 0.0001
p = 0.90: 0.0000</pre>
With LDC2 compiler this code
=={{header|Python}}==
|