-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem01.ml
More file actions
28 lines (23 loc) · 786 Bytes
/
problem01.ml
File metadata and controls
28 lines (23 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
open Printf
let rec sum num acc =
match num with
| 1000 -> acc
| _ -> if (((num mod 3) == 0) or ((num mod 5) == 0)) then
begin
printf "%d\n" num;
sum (num+1) (acc+num)
end
else sum (num+1) acc;;
let rec sum3 num acc =
match num with
| n when n >= 1000-> acc
| _ -> printf "%d\n" num; sum3 (num+3) (acc+num);;
let rec sum5 num acc =
match num with
| n when n >= 1000 -> acc
| _ -> printf "%d\n" num; sum5 (num+5) (acc+num);;
let rec rem15 num acc =
match num with
| n when n >= 1000 -> acc
| _ -> printf "%d\n" num; rem15 (num+15) (acc+num);;
let sumpro = (sum3 0 0) + (sum5 0 0) - (rem15 0 0);;