联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Web作业Web作业

日期:2024-04-16 04:36

CS314 Assignment 7

1    OCaml Basics

(1) Write an OCaml function maxAbsoluteVal : int list → int that takes an

integer list l and returns the maximum absolute value of l. Examples:

# maxAbsoluteVal [ ] ;;

- : int = 0

# maxAbsoluteVal [1;2;3;-4];;

- : int = 4

(2) Write an OCaml function getnthdigit :  int → int that gets then-th digit

of an integer.

Examples:

# getnthdigit 12345 1;;

- : int = 1

# getnthdigit 31145 5;;

- : int = 5

(3)  Implement prefix sum in OCaml, psum :  int list → int list.  The prefix sum algorithm takes a sequence of numbers x0 , x1 , x2 , ... as input and returns  a  sequence of numbers y0 , y1 , y2 , ... such that y0   =  x0 , y1   =

x0 + x1 , y2  = x0 + x1 + x2  and so on.

Examples:

# psum [1; 2; 0; -7] ;;

- : int list = [1; 3; 3; -4] ;;

# psum [0; 1; 2; 3] ;;

- : int list = [0; 1; 3; 6]

# psum [ ] ;;

- : int list = [ ]

Note: You are not allowed to use OCaml’s imperative features.




版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp