lambdaway
::
randomwalk
6
|
list
|
login
|
load
|
|
{{SVG 580 580 #888} {g {AXES 580 580} {path {@ d="M 0 0 C {XY 0 0 8 200}" {stroke #000 8}}} {path {@ d="M 0 0 C {XY 0 0 8 200}" {stroke #f00 7}}} {path {@ d="M 0 0 C {XY 0 0 8 200}" {stroke #0f0 6}}} {path {@ d="M 0 0 C {XY 0 0 8 200}" {stroke #00f 5}}} {path {@ d="M 0 0 C {XY 0 0 8 200}" {stroke #ff0 4}}} {path {@ d="M 0 0 C {XY 0 0 8 200}" {stroke #f0f 3}}} {path {@ d="M 0 0 C {XY 0 0 8 200}" {stroke #0ff 2}}} {path {@ d="M 0 0 C {XY 0 0 8 200}" {stroke #fff 1}}} }} {center Rafraîchir la page pour voir la réalisation de 8 autres marches aléatoires.} _h1 random walks _p Following: _ul [[https://fr.wikipedia.org/wiki/Marche_aléatoire|https://fr.wikipedia.org/wiki/Marche_aléatoire]] _ul [[codespeedy|https://www.codespeedy.com/random-walk-program-in-python/]] _ul [[https://fr.acervolima.com/random-walk-implementation-en-python/|https://fr.acervolima.com/random-walk-implementation-en-python/]] _ul [[https://www.lptmc.jussieu.fr/user/sator/Chapitre2.pdf|https://www.lptmc.jussieu.fr/user/sator/Chapitre2.pdf]] _ul [[https://www.techno-science.net/glossaire-definition/Marche-aleatoire|https://www.techno-science.net/glossaire-definition/Marche-aleatoire-page-3.html]] _ul ... _p Chaque courbe représente une marche aléatoire. Chaque pas du marcheur se fait selon une des 4 directions (vers l'est, l'ouest, le nord ou le sud). Le choix de la direction de chaque pas est issu du hasard, avec équiprobabilité pour chacune des éventualités. Voir la preuve à la page [[frequency3]]. {pre ;; {A.sort! < {A.new {S.map walk.direction {S.serie 0 100}}}} '{def walk.direction // -> [0 1 2 3] -> EAST, WEST, NORTH, SOUTH {lambda {} {floor {* 4 {random}}}}} // merci Christophe -> {def walk.direction ;; Math.floor(Math.random() * (max - min + 1)) + min {lambda {} {floor {* 4 {random}}}}} '{def walk.u {lambda {:u :dir :step} {if {= :dir 0} then {+ :u :step} else {if {= :dir 1} then {- :u :step} else :u }} }} // les deux autres cas, 2 & 3 -> {def walk.u {lambda {:u :dir :step} {if {= :dir 0} then {+ :u :step} else {if {= :dir 1} then {- :u :step} else :u }} }} '{def walk.v {lambda {:v :dir :step} {if {= :dir 2} then {+ :v :step} else {if {= :dir 3} then {- :v :step} else :v }} }} // les deux autres cas 0 & 1 -> {def walk.v {lambda {:v :dir :step} {if {= :dir 2} then {+ :v :step} else {if {= :dir 3} then {- :v :step} else :v }} }} '{def walk {def walk.rec {lambda {:x :y :step :n :i} {if {= :i :n} then {A.new :x :y} else {let { {:x :x} {:y :y} {:step :step} {:n :n} {:i :i} {:dir {walk.direction}} } {walk.rec {A.addlast! {walk.u {A.get {- :i 1} :x} :dir :step} :x} {A.addlast! {walk.v {A.get {- :i 1} :y} :dir :step} :y} :step :n {+ :i 1}}}}}} {lambda {:x :y :step :n} {walk.rec {A.new :x} {A.new :y} :step :n 1}}} -> {def walk {def walk.rec {lambda {:x :y :step :n :i} {if {= :i :n} then {A.new :x :y} else {let { {:x :x} {:y :y} {:step :step} {:n :n} {:i :i} {:dir {walk.direction}} } {walk.rec {A.addlast! {walk.u {A.get {- :i 1} :x} :dir :step} :x} {A.addlast! {walk.v {A.get {- :i 1} :y} :dir :step} :y} :step :n {+ :i 1}}}}}} {lambda {:x :y :step :n} {walk.rec {A.new :x} {A.new :y} :step :n 1}}} '{def XY {lambda {:x :y :step :n} {S.map {{lambda {:xy :i} {A.get :i {A.first :xy}} {A.get :i {A.last :xy}} } {walk :x :y :step :n}} {S.serie 1 :n}}}} -> {def XY {lambda {:x :y :step :n} {S.map {{lambda {:xy :i} {A.get :i {A.first :xy}} {A.get :i {A.last :xy}} } {walk :x :y :step :n}} {S.serie 1 :n}}}} '{{SVG 580 580 #888} {g {AXES 580 580} {path {@ d="M 0 0 C {XY 0 0 8 250}" {stroke #000 8}}} {path {@ d="M 0 0 C {XY 0 0 8 250}" {stroke #f00 7}}} {path {@ d="M 0 0 C {XY 0 0 8 250}" {stroke #0f0 6}}} {path {@ d="M 0 0 C {XY 0 0 8 250}" {stroke #00f 5}}} {path {@ d="M 0 0 C {XY 0 0 8 250}" {stroke #ff0 4}}} {path {@ d="M 0 0 C {XY 0 0 8 250}" {stroke #f0f 3}}} {path {@ d="M 0 0 C {XY 0 0 8 250}" {stroke #0ff 2}}} {path {@ d="M 0 0 C {XY 0 0 8 250}" {stroke #fff 1}}} }} } _p {i 2022/10/18} {{hide} {def SVG {lambda {:w :h :c} svg {@ width=":wpx" height=":hpx" style="background::c; box-shadow:0 0 8px #000;"} }} {def AXES {lambda {:w :h} {@ transform="translate({/ :w 2},{/ :h 2}) scale(-1,-1)"} {line {@ x1="-{/ :w 2}:w" y1="0" x2="{/ :w 2}" y2="0" stroke="red" fill="transparent"}} {line {@ x1="0" y1="-{/ :h 2}" x2="0" y2="{/ :h 2}" stroke="green" fill="transparent"}} }} {def stroke {lambda {:col :w} stroke=":col" fill="transparent" stroke-width=":w" }} }
lambdaway v.20211111