diff --git a/sand.flan b/sand.flan index 60bb8ed..f683bac 100644 --- a/sand.flan +++ b/sand.flan @@ -25,6 +25,28 @@ (defonce velocity [rows [cols f32]]) (defonce current-color dyn 0) +(defn insertion-sort [coll [$t]] () + {:where (ordered? $t)} + (let [i 1 + length (len coll)] + (while (and (< i length)) + (let [j i] + (while (and (> j 0) + (< (at coll j) (at coll (dec j)))) + (let [temp (at coll j)] + (set (at coll j) (at coll (dec j))) + (set (at coll (dec j)) temp)) + (-- j))) + (++ i)))) + +(comment + (insertion-sort [\I \N \S \E \R \T \I \O \N \S \O \R \T]) + (insertion-sort (slice [6 2 4 9 1 9 4 5] 0 8)) + (let [str (bytes "INSERTIONSORT")] + (insertion-sort str) + (println str)) + :-) + (defn clear-grid [] () (set grid (zeroed)) (set velocity (zeroed))) @@ -41,7 +63,7 @@ (when (and (>= r 0) (< r (- rows 1)) (>= c 0) (< c (- cols 1)) (= 0 (at grid r c)) - (< (rand-f32) 0.5)) + (< (f32 (rand)) 0.5)) (set (at grid r c) (dyn->u32 (at colors current-color))) (set (at velocity r c) 1.0))))))) @@ -61,7 +83,7 @@ (let [side (cond (not left?) 1 (not right?) -1 - :else (if (< (rand-f32) 0.5) 1 -1))] + :else (if (< (f32 (rand)) 0.5) 1 -1))] (set (at grid y (+ col side)) (at grid row col)) (set (at grid row col) 0) (set (at velocity y (+ col side)) vel) diff --git a/test/test_acceptance.ml b/test/test_acceptance.ml index 2e47da7..8af1369 100644 --- a/test/test_acceptance.ml +++ b/test/test_acceptance.ml @@ -2267,12 +2267,11 @@ let () = libraylib on every target, and this one is the version meant to run on wasm32 too. The hash is reproducible only because rand is ours. - The number below is the *old* generator's grid and cannot be right - again: a draw is 64 bits now and every grain lands somewhere else. When - sand.flan is brought up to date and these rows run again, the hash is - re-taken from the run — that is the one manual step, and it is the - normal one for this case. *) - let sand_out = "15595743031174623232\n" in + The number below was re-taken when the generator changed: a draw is 64 + bits now and every grain lands somewhere else, so the old grid's hash + could not be right again. Re-taking it from a run is the one manual + step, and it is the normal one for this case. *) + let sand_out = "7623511701454096497\n" in if sand_checks then begin outputs "sand, headless" "programs/sand-headless.flan" sand_out; outputs ~opt:"-O0" "sand, headless, -O0" "programs/sand-headless.flan"