This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s = Array.Unsafe.set | |
let g = Array.get | |
let g2 = Matrix.get | |
let s2 = Matrix.Unsafe.set | |
let swap a (i0, j0) (i1, j1) = | |
let t = g2 a (i0, j0) in | |
let () = g2 a (i1, j1) @ s2 a (i0, j0) in | |
s2 a (i1, j1) t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cholesky zero √ conj a = | |
let get = Matrix.get in | |
let set = Matrix.set in | |
let n = Matrix.checkSquare a in | |
let l = Matrix.zero n n in | |
let () = | |
for 0 1 (n-1) () [(), j -> | |
for j 1 (n-1) () [(), i -> | |
let psum = | |
for 0 1 (j-1) 0 [psum, k -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ff ((rx, ry), i) = | |
if i=3000 then None else | |
let ((a,b),(c,d)), (vx,vy) = | |
let r = Random.next 100 in | |
if r < 75 then ((85, 4), (-4, 85)), (0, 160) | |
else if r < 88 then ((-15, 28), (-26, 24)), (0, 44) | |
else if r < 98 then ((20, -26), (23, 22)), (0, 160) | |
else ((0, 0), (0, 16)), (0, 0) in | |
Some((rx, ry), (((a*rx+b*ry+vx)/100, (c*rx+d*ry+vy)/100), i+1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Nation = British | Swedish | Danish | Norwegian | German | |
type House = Red | Green | Blue | White | Yellow | |
type Drink = Milk | Coffee | Water | Beer | Tea | |
type Smoke = PallMall | Dunhill | Marlboro | Rothmans | Winfield | |
type Pet = Dog | Cat | Fish | Horse | Bird | |
let nations = {British; Swedish; Danish; Norwegian; German} | |
let houses = {Red; Green; Blue; White; Yellow} | |
let drinks = {Milk; Coffee; Water; Beer; Tea} | |
let smokes = {PallMall; Dunhill; Marlboro; Rothmans; Winfield} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let distance s1 s2 = | |
let indexable s = | |
let a = Array.ofString s in | |
Array.length a, Array.get a in | |
let (m, u), (n, v) = indexable s1, indexable s2 in | |
let d1 = Array.init n id in | |
let d0 = Array.init n [_ → 0] in | |
let () = for 1 1 (m-1) () [(), i → | |
let () = Array.Unsafe.set d0 0 i in | |
let ui = u i in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ! = Array.get | |
let x (x, _) = x | |
let y (_, y) = y | |
let add (x1,y1) (x2,y2) = x2+x1, y2+y1 | |
let sub (x1,y1) (x2,y2) = x2-x1, y2-y1 | |
let scale s (x,y) = s*x, s*y | |
let dot (x1,y1) (x2,y2) = x1*x2 + y1*y2 | |
let length u = √(dot u u) | |
let cross (x1,y1) (x2,y2) = x1*y2 - x2*y1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let det₃((a₁₁,a₁₂,a₁₃),(a₂₁,a₂₂,a₂₃),(a₃₁,a₃₂,a₃₃)) = | |
-a₁₃*a₂₂*a₃₁ + a₁₂*a₂₃*a₃₁ + a₁₃*a₂₁*a₃₂ - | |
a₁₁*a₂₃*a₃₂ - a₁₂*a₂₁*a₃₃ + a₁₁*a₂₂*a₃₃ | |
let createCircle ((x₁, y₁), (x₂, y₂), (x₃, y₃)) = | |
let a = det₃((x₁, y₁, 1), (x₂, y₂, 1), (x₃, y₃, 1)) in | |
let d = -det₃((sqr x₁ + sqr y₁, y₁, 1), (sqr x₂ + sqr y₂, y₂, 1), (sqr x₃ + sqr y₃, y₃, 1)) in | |
let e = det₃((sqr x₁ + sqr y₁, x₁, 1), (sqr x₂ + sqr y₂, x₂, 1), (sqr x₃ + sqr y₃, x₃, 1)) in | |
let f = -det₃((sqr x₁ + sqr y₁, x₁, y₁), (sqr x₂ + sqr y₂, x₂, y₂), (sqr x₃ + sqr y₃, x₃, y₃)) in | |
let r = (sqr d + sqr e)/(4 * sqr a) - f/a @ sqrt in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type rec AATree a = E | T(Number, AATree a, a, AATree a) | |
let empty = E | |
let isEmpty = [E → True | T _ → False] | |
let rec count = | |
[ E → 0 | |
| T(_, l, _, r) → count l + 1 + count r ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let zero = 0, 0, 0 | |
let scale s (x, y, z) = s*x, s*y, s*z | |
let add (x1,y1,z1) (x2,y2,z2) = x1+x2, y1+y1, z1+z2 | |
let sub (x1,y1,z1) (x2,y2,z2) = x1-x2, y1-y1, z1-z2 | |
let dot (x1,y1,z1) (x2,y2,z2) = x1*x2 + y1*y1 + z1*z2 | |
let unitise u = scale (1/√(dot u u)) u | |
type rec Scene = | |
| Sphere | |
| Bound(Array((Number, Number, Number), Number, Scene)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Concestor(Key: Collections.HASH) : sig | |
type 'v t | |
val empty : unit -> 'v t | |
val is_empty : 'v t -> bool | |
val add : Key.t -> 'v -> 'v t -> 'v t | |
val remove : Key.t -> 'v t -> 'v t | |
val mem : Key.t -> 'v t -> bool | |
val find : Key.t -> 'v t -> 'v | |
val find_opt : Key.t -> 'v t -> 'v option |