Replies: 2 comments
-
The error that appears whenever i try to launch the code: |
Beta Was this translation helpful? Give feedback.
0 replies
-
labels is a reserved name, see https://maxima.sourceforge.io/docs/manual/maxima_8.html#index-labels-1 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
`percolation(matrix, labels) :=
block(
label: 0,
label_of: makelist(makelist(0, j, 1, length(matrix[1])), i, 1, length(matrix)),
connected: lambda([label1, label2], label1 = label2),
find_root: lambda([label], if labels[label] = label then label else find_root(labels[label])),
union: lambda([label1, label2], labels[find_root(label1)]: find_root(label2)),
for i thru length(matrix) do
for j thru length(matrix[i]) do
if matrix[i][j] = 1 then
if i = 1 and j = 1 then (
label: label + 1,
push(label, labels)
) else if i = 1 then
if matrix[i][j-1] = 1 then
label_of[i][j]:= label_of[i][j-1]
else (
label: label + 1,
push(label, labels),
label_of[i][j]:= label
)
else if j = 1 then
if matrix[i-1][j] = 1 then
label_of[i][j]:= label_of[i-1][j]
else (
label: label + 1,
push(label, labels),
label_of[i][j]:= label
)
else if matrix[i][j-1] = 1 and matrix[i-1][j] = 1 then (
label_of[i][j]:= min(label_of[i][j-1], label_of[i-1][j]),
union(label_of[i][j-1], label_of[i-1][j])
) else if matrix[i][j-1] = 1 then
label_of[i][j]:= label_of[i][j-1]
else if matrix[i-1][j] = 1 then
label_of[i][j]:= label_of[i-1][j]
else (
label: label + 1,
push(label, labels),
label_of[i][j]:= label
),
for i thru length(labels) do
labels[i]:= find_root(labels[i]),
num_components: length(uniq(labels)),
if num_components > 1 then (
print("Perkolacja występuje"),
print("Liczba składowych: ", num_components)
) else
print("Perkolacja nie występuje")
);
matrix: [[8, 7, 9, 10, 11],
[10, 5, 9, 3, 3],
[7, 6, 4, 7, 2],
[11, 9, 7, 9, 8]];
labels: [];
percolation(matrix, labels);`
Beta Was this translation helpful? Give feedback.
All reactions