Jump to content

Percolation/Site percolation/J: Difference between revisions

m
no edit summary
mNo edit summary
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 10:
<code>groups</code> uses a sum fold on successive prefixes to identify regions of contiguous bits.
 
<lang j> 12 10 12 0 1 0 1 10 0 1 01 1 1 0 1 10
12 10 12 0 1 0 1 10 0 1 01 1 1 0 1 10
* 2 </\0 2 0, 1 10 1 0 0 1 1 0 1 0 1 1 0 1 1
1 0 01 0 1 0 1 0 0 1 01 1 0 01 1 0
+/\(0, *) 2 </\0 2 0, 1 10 1 0 0 1 1 0 1 0 1 1 0 1 1
10 1 10 1 0 1 20 21 20 30 31 41 41 41 51 5</lang>0
(2 </\ 0, *) 2 0 2 0 1 0 1 0 0 1 1 1 1 1 0
1 0 1 0 1 0 1 0 0 1 0 0 0 0 0
([: +/\ 2 </\ 0, *) 2 0 2 0 1 0 1 0 0 1 1 1 1 1 0
1 1 2 2 3 3 4 4 4 5 5 5 5 5 5</lang>
 
<code>ooze</code> propagates 2s from its right argument to adjacent groups of non-zero locations in its left argument.
Line 33 ⟶ 37:
2 0 2 0 1 0 1 0 0 1 1 1 1 1 0 ([ >. [ +&* [ * [: ; groups@[ <@(* * 2 < >./)/. +) 0 0 1 1 1 1 0 2 0 2 0 1 1 1 1
2 0 2 0 1 0 1 0 0 2 2 2 2 2 0</lang>
 
Note that u/. uses the key in the left argument to gather corresponding values from the right argument (which are then processed by <code>u</code>).
 
<lang j> 2 0 2 0 1 0 1 0 0 1 1 1 1 1 0 (groups@[ </. +) 0 0 1 1 1 1 0 2 0 2 0 1 1 1 1
┌───┬───┬───┬─────┬───────────┐
│2 0│3 1│2 1│1 2 0│3 1 2 2 2 1│
└───┴───┴───┴─────┴───────────┘
2 0 2 0 1 0 1 0 0 1 1 1 1 1 0 (groups@[ <@(>./)/. +) 0 0 1 1 1 1 0 2 0 2 0 1 1 1 1
┌─┬─┬─┬─┬─┐
│2│3│2│2│3│
└─┴─┴─┴─┴─┘
2 0 2 0 1 0 1 0 0 1 1 1 1 1 0 (groups@[ <@(2 < >./)/. +) 0 0 1 1 1 1 0 2 0 2 0 1 1 1 1
┌─┬─┬─┬─┬─┐
│0│1│0│0│1│
└─┴─┴─┴─┴─┘
2 0 2 0 1 0 1 0 0 1 1 1 1 1 0 (groups@[ <@(* * 2 < >./)/. +) 0 0 1 1 1 1 0 2 0 2 0 1 1 1 1
┌───┬───┬───┬─────┬───────────┐
│0 0│1 1│0 0│0 0 0│1 1 1 1 1 1│
└───┴───┴───┴─────┴───────────┘</lang>
 
We use +&* because 1 +&* 2 is 2, but also 2 +&* 2 is 2:
Line 178 ⟶ 201:
2 2 2 0 2 2 0 0 2 0 2 0 0 1 1</lang>
 
(^:_ repeats an operation until it reaches a [[wp:Fixed_point_(mathematics)|fixed point]]. In other words, it's basically a while loop.)
 
<code>trial</code> generates an arbitrary connection matrix and runs percolate on it. You'll typically get a different result from each trial.
Line 231 ⟶ 254:
1 1 0 1 0 1 1 1 1 1 1 0 1 1 0
0 1 1 1 0 0 1 1 0 1 1 0 0 0 0
1 1 0 1 0 1 1 1 1 0 0 1 1 1 0</lang>
0.6 percolate@([ >: ] ?@$ 0:) 15 15
0 0 0 0 2 2 2 2 2 0 2 0 0 0 2
0 1 0 2 0 2 2 0 2 0 2 2 0 0 0
1 0 2 2 2 2 2 2 2 0 0 2 0 0 1
0 2 2 0 2 0 2 0 2 0 2 2 2 0 1
2 2 2 2 0 2 2 2 2 0 2 2 0 0 1
2 2 2 0 1 0 2 2 0 0 2 2 2 2 0
0 0 2 2 0 0 2 2 2 0 2 2 0 2 2
0 2 2 0 0 2 2 2 2 2 0 2 2 0 2
0 2 0 0 0 2 0 0 0 0 0 2 2 0 0
0 2 0 2 2 2 2 0 2 2 2 2 0 0 0
0 2 2 2 2 2 0 0 2 2 2 0 1 0 2
2 0 2 0 0 0 2 2 0 0 0 0 0 0 2
2 2 2 2 2 2 2 2 2 2 2 2 0 2 2
0 0 2 2 2 2 0 2 2 0 0 2 2 2 0
0 1 0 0 2 0 2 2 0 0 1 0 2 0 1</lang>
 
<code>simulate</code> runs a sequence of 15 by 15 trials and averages them. Since each trial is different, each run of simulate is different.
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.