Percolation/Site percolation: Difference between revisions
m
→{{header|11l}}: Void
m (Altered code to be more C++ idiomatic.) |
Alextretyak (talk | contribs) m (→{{header|11l}}: Void) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 48:
print(‘!) ’(‘ ’ * where)‘’:cell2char[cell[:nn - 1][where]])
F walk_maze(m, n, &cell, indx) X(PercolatedException) ->
cell[n][m] = indx
I n < :nn - 1 & cell[n + 1][m] == :NOT_VISITED
Line 63:
F check_from_top(&cell) -> (Int, Int)?
V (n, walk_index) = (0, 1)
walk_maze(m, n, &cell, walk_index
R ex.t▼
▲ X.catch PercolatedException ex
▲ R ex.t
R N
Line 399 ⟶ 398:
bool percolate() {
for ( int32_t x = 0; x < (int32_t) table[0].size();
if ( path_exists(x, 0) ) {
return true;
Line 408 ⟶ 407:
void display() const {
for ( uint64_t col = 0; col < table.size();
for ( uint64_t row = 0; row < table[0].size();
std::cout << " " << table[col][row];
}
Line 430 ⟶ 429:
void create_table(const int32_t row_count, const int32_t col_count, const double probability) {
table.assign(row_count, std::vector<std::string>(col_count, EMPTY));
for ( int32_t col = 0; col < row_count;
for ( int32_t row = 0; row < col_count;
table[col][row] = ( distribution(generator) < probability ) ? FILLED: EMPTY;
}
Line 454 ⟶ 453:
std::cout << "Proportion of " << test_count << " tests that percolate through the grid:" << std::endl;
for ( double probable = 0.0; probable <= 1.0; probable += 0.1 ) {
for ( int32_t test = 0; test < test_count;
Grid test_grid(row_count, col_count, probable);
if ( test_grid.percolate() ) {
percolation_count += 1.0;
}
}
const double percolation_proportion =
std::cout << " p = " << std::setprecision(1) <<std::fixed << probable << " : "
<< std::setprecision(4) << percolation_proportion << std::endl;
}
}
Line 2,542:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="
import "./fmt" for Fmt
var rand = Random.new()
|