编写一个名为month_range 的函数,它将一年中名为day_one 和day_two 的两天(例如65、128,假设一年有365 天)作为输入并返回其月份的int 列表。必须day_two - day_one + 1;
知道这个 int 列表的大小,如果 day_one>day_two,则列表大小 = 0
示例:month_range(25,36) should return [1,1,1,1,1,1,1,2,2,2,2,2]
一月(25,26,27,..,31) 和二月(1,2,..,5)
我写了代码,但它不起作用:
fun month_range (day1:int,day2:int) =
let
val month_days= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
fun what_month(day :int) =
let
fun aux(sum :int, numbers: int list) =
let
val numbers_tail = tl numbers
in
if sum <= (hd numbers)
then 1
else
1 + aux(sum, (hd numbers + hd numbers_tail)::(tl numbers_tail))
end
in
aux(day, month_days)
end
in
if (day1>day2)
then []
else what_month(day1) @ what_month(day2)
end