57 lines
957 B
Tcl
57 lines
957 B
Tcl
![]() |
load ./q3.so
|
||
|
source symul_lib.tcl
|
||
|
|
||
|
|
||
|
# tworzenie kraty k x k
|
||
|
set k 3
|
||
|
set liczbaWierz [expr $k*$k]
|
||
|
|
||
|
iterate i $liczbaWierz {
|
||
|
set sasiedzi($i) {}
|
||
|
}
|
||
|
|
||
|
set k1 [expr $k-1]
|
||
|
proc nr {x y} {global k; expr $x*$k+$y}
|
||
|
|
||
|
iterate x $k1 {
|
||
|
iterate y $k1 {
|
||
|
set i [nr $x $y]; DodajKraw $i [expr {$i+1}]; DodajKraw $i [expr {$i+$k}]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
iterate x $k1 {
|
||
|
set i [nr $x $k1]; DodajKraw $i [expr $i+$k]
|
||
|
}
|
||
|
|
||
|
iterate y $k1 {
|
||
|
set i [nr $k1 $y]; DodajKraw $i [expr $i+1]
|
||
|
}
|
||
|
|
||
|
# efekt
|
||
|
array get sasiedzi
|
||
|
|
||
|
|
||
|
# definicja wierzchołka
|
||
|
fiber create $liczbaWierz {
|
||
|
set list $id
|
||
|
while {$run} {
|
||
|
for {set i 0} {$i < $stopien} {incr i} {
|
||
|
if {$kom($i)!=""} {
|
||
|
set list "$list$kom($i)"
|
||
|
while {[regsub -all {(.)(.*)\1+} $list {\1\2} list]} {}
|
||
|
}
|
||
|
}
|
||
|
for {set i 0} {$i < $stopien} {incr i} {
|
||
|
wyslij $i $list
|
||
|
}
|
||
|
fiber yield
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Inicjalizacja;
|
||
|
|
||
|
proc wizualizacja {} {
|
||
|
fiber_iterate {_puts "id: $id, lista: $list"}
|
||
|
}
|
||
|
|
||
|
fiber yield; runda; wizualizacja
|