Skip to content

Instantly share code, notes, and snippets.

View cohalz's full-sized avatar
🌴
On vacation

cohalz cohalz

🌴
On vacation
View GitHub Profile
let bmi_check (name, height, weight) =
let bmi = weight /. (height *. height) in
if bmi < 18.5 then name ^ "さんはやせています"
else if bmi < 25.0 then name ^ "さんは標準です"
else if bmi < 30.0 then name ^ "さんは肥満です"
else name ^ "さんは肥満です"
let geo_mean x y = sqrt(x *. y)
let sum_and_diff (x, y) = (x + y, x - y)
let f (x, y) = ((x+y)/2,(x-y)/2)
let rec pow(x,n) =
if n <= 1 then x else x * pow(x,n-1)
let rec pow(x,n) =
if n <= 1 then x
else let stack = pow(x,n/2) in
if n mod 2 = 0 then stack*stack
else x*stack*stack
let rec iterpow(i,res,x,n) =
if i > n then res else iterpow(i+1,res *. x,x,n)
let rec gcd (m,n) =
if m mod n = 0 then n else gcd(n,m mod n)
let rec comb(n,m) =
if m = 0 || n = m then 1
else comb(n-1,m) + comb(n-1,m-1)
let fib n =
let rec iterfib(i,pre2,pre1,res,n) =
if i >= n then res else iterfib(i+1,pre1,res,res+pre1,n) in
iterfib(1,0,0,1,n)
let max_ascii str =
let rec itermax(i,str,max,length) =
if i >= length then max
else if int_of_char(str.[i]) > max then itermax(i+1,str,int_of_char(str.[i]),length)
else itermax(i+1,str,max,length) in
itermax(0,str,0,String.length str)