Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Map-range/OCaml/map-range-1.ocaml
Normal file
8
Task/Map-range/OCaml/map-range-1.ocaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let map_range (a1, a2) (b1, b2) s =
|
||||
b1 +. ((s -. a1) *. (b2 -. b1) /. (a2 -. a1))
|
||||
|
||||
let () =
|
||||
print_endline "Mapping [0,10] to [-1,0] at intervals of 1:";
|
||||
for i = 0 to 10 do
|
||||
Printf.printf "f(%d) = %g\n" i (map_range (0.0, 10.0) (-1.0, 0.0) (float i))
|
||||
done
|
||||
11
Task/Map-range/OCaml/map-range-2.ocaml
Normal file
11
Task/Map-range/OCaml/map-range-2.ocaml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
let map_range (a1, a2) (b1, b2) =
|
||||
let v = (b2 -. b1) /. (a2 -. a1) in
|
||||
function s ->
|
||||
b1 +. ((s -. a1) *. v)
|
||||
|
||||
let () =
|
||||
print_endline "Mapping [0,10] to [-1,0] at intervals of 1:";
|
||||
let p = (map_range (0.0, 10.0) (-1.0, 0.0)) in
|
||||
for i = 0 to 10 do
|
||||
Printf.printf "f(%d) = %g\n" i (p (float i))
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue