Area Under Curves and Volume of Revolving a Curve Discussions | Functional Programming | HackerRank
We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
letpolynomialcoefsexpsx=letzip=List.combinecoefsexpsinList.fold_left(+.)0.0(List.map(fun(coef,exp)->coef*.(x**exp))zip)letdefinite_integral~f_poly~a~b~interval=letrecrangelowerupperstep=iflower>upperthen[]elselower::range(lower+.step)upperstepinletintervals=rangeabintervalinList.fold_left(+.)0.0(List.map(funx->f_polyx*.interval)intervals)letvolume_integral~f_poly~a~b~interval=letrecrangelowerupperstep=iflower>upperthen[]elselower::range(lower+.step)upperstepinletintervals=rangeabintervalinletpi=4.0*.atan1.0inList.fold_left(+.)0.0(List.map(funx->pi*.(f_polyx**2.0)*.interval)intervals)letcoefs=stdin|>input_line|>String.split_on_char' '|>List.mapfloat_of_stringletexps=stdin|>input_line|>String.split_on_char' '|>List.mapfloat_of_stringletlimits=stdin|>input_line|>String.split_on_char' '|>List.mapfloat_of_stringlet(a,b)=matchlimitswith|[a;b]->(a,b)|_->failwith"Limit must be only two arguments"letauc=definite_integral~f_poly:(polynomialcoefsexps)~a:a~b:b~interval:0.001letvuc=volume_integral~f_poly:(polynomialcoefsexps)~a:a~b:b~interval:0.001let()=print_endline(string_of_floatauc)let()=print_endline(string_of_floatvuc)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Area Under Curves and Volume of Revolving a Curve
You are viewing a single comment's thread. Return to all comments →
Ocaml solution: