Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
27
Task/Vector/OCaml/vector.ocaml
Normal file
27
Task/Vector/OCaml/vector.ocaml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
module Vector =
|
||||
struct
|
||||
type t = { x : float; y : float }
|
||||
let make x y = { x; y }
|
||||
let add a b = { x = a.x +. b.x; y = a.y +. b.y }
|
||||
let sub a b = { x = a.x -. b.x; y = a.y -. b.y }
|
||||
let mul a n = { x = a.x *. n; y = a.y *. n }
|
||||
let div a n = { x = a.x /. n; y = a.y /. n }
|
||||
|
||||
let to_string {x; y} = Printf.sprintf "(%F, %F)" x y
|
||||
|
||||
let ( + ) = add
|
||||
let ( - ) = sub
|
||||
let ( * ) = mul
|
||||
let ( / ) = div
|
||||
end
|
||||
|
||||
open Printf
|
||||
|
||||
let test () =
|
||||
let a, b = Vector.make 5. 7., Vector.make 2. 3. in
|
||||
printf "a: %s\n" (Vector.to_string a);
|
||||
printf "b: %s\n" (Vector.to_string b);
|
||||
printf "a+b: %s\n" Vector.(a + b |> to_string);
|
||||
printf "a-b: %s\n" Vector.(a - b |> to_string);
|
||||
printf "a*11: %s\n" Vector.(a * 11. |> to_string);
|
||||
printf "a/2: %s\n" Vector.(a / 2. |> to_string)
|
||||
Loading…
Add table
Add a link
Reference in a new issue