From f8db69541ad30381156302dfe35d4440691c2e91 Mon Sep 17 00:00:00 2001 From: pmpknu Date: Sun, 27 Oct 2024 23:14:28 +0300 Subject: [PATCH 01/13] feat(p19): add solution in python --- p19/solution.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 p19/solution.py diff --git a/p19/solution.py b/p19/solution.py new file mode 100644 index 0000000..6d19e27 --- /dev/null +++ b/p19/solution.py @@ -0,0 +1,11 @@ +from datetime import datetime, timedelta + +sundays_count = 0 + +for year in range(1901, 2001): + for month in range(1, 13): + first_day = datetime(year, month, 1) + if first_day.weekday() == 6: + sundays_count += 1 + +print(sundays_count) From 9dce46e3cdd88e79dfaf35035deaf31cef07af42 Mon Sep 17 00:00:00 2001 From: pmpknu Date: Mon, 28 Oct 2024 09:54:29 +0300 Subject: [PATCH 02/13] feat(p19): add is_leap function - add the is_leap handler function, which returns whether the year leaps or not. --- p19/lib/date.ml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 p19/lib/date.ml diff --git a/p19/lib/date.ml b/p19/lib/date.ml new file mode 100644 index 0000000..ce8f290 --- /dev/null +++ b/p19/lib/date.ml @@ -0,0 +1,2 @@ +let is_leap year = + (year mod 4 = 0 && year mod 100 <> 0) || (year mod 400 = 0) From 7973a0015279228a5ecbfc00adbad01ad4cee8f0 Mon Sep 17 00:00:00 2001 From: pmpknu Date: Mon, 28 Oct 2024 09:59:13 +0300 Subject: [PATCH 03/13] feat(p19): add days_in_month function - function returns amount of days in month according to year --- p19/lib/date.ml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/p19/lib/date.ml b/p19/lib/date.ml index ce8f290..f8ea242 100644 --- a/p19/lib/date.ml +++ b/p19/lib/date.ml @@ -1,2 +1,9 @@ let is_leap year = (year mod 4 = 0 && year mod 100 <> 0) || (year mod 400 = 0) + +let days_in_month year month = + match month with + | 1 | 3 | 5 | 7 | 8 | 10 | 12 -> 31 + | 4 | 6 | 9 | 11 -> 30 + | 2 -> if is_leap year then 29 else 28 + | _ -> failwith "Invalid month" \ No newline at end of file From 4b4aff6b05ace1c177645039612c98ef37516e64 Mon Sep 17 00:00:00 2001 From: pmpknu Date: Mon, 28 Oct 2024 11:07:05 +0300 Subject: [PATCH 04/13] feat(p19): add dune date lib --- p19/lib/dune | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 p19/lib/dune diff --git a/p19/lib/dune b/p19/lib/dune new file mode 100644 index 0000000..9561153 --- /dev/null +++ b/p19/lib/dune @@ -0,0 +1,3 @@ +(library + (name p19_date) + (modules date)) \ No newline at end of file From 58e305fa2d2cc759b0a0707ab2c481817d0ed8a0 Mon Sep 17 00:00:00 2001 From: pmpknu Date: Mon, 28 Oct 2024 11:17:28 +0300 Subject: [PATCH 05/13] feat(p19): add tailrec solution implementation - also add dune config - also add date interface --- p19/lib/date.mli | 1 + p19/lib/dune | 4 ++-- p19/lib/tailrec.ml | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 p19/lib/date.mli create mode 100644 p19/lib/tailrec.ml diff --git a/p19/lib/date.mli b/p19/lib/date.mli new file mode 100644 index 0000000..ba35e56 --- /dev/null +++ b/p19/lib/date.mli @@ -0,0 +1 @@ +val days_in_month : int -> int -> int diff --git a/p19/lib/dune b/p19/lib/dune index 9561153..75f9e0a 100644 --- a/p19/lib/dune +++ b/p19/lib/dune @@ -1,3 +1,3 @@ (library - (name p19_date) - (modules date)) \ No newline at end of file + (name p19_lib) + (modules date tailrec)) diff --git a/p19/lib/tailrec.ml b/p19/lib/tailrec.ml new file mode 100644 index 0000000..6d98313 --- /dev/null +++ b/p19/lib/tailrec.ml @@ -0,0 +1,12 @@ +open Date + +let rec count_sundays year month day_of_week count = + if year > 2000 then count + else + let new_count = if day_of_week = 0 then count + 1 else count in + let days_this_month = days_in_month year month in + let next_day_of_week = (day_of_week + days_this_month) mod 7 in + if month == 12 then + count_sundays (year + 1) 1 next_day_of_week new_count + else + count_sundays year (month + 1) next_day_of_week new_count From 2e79989eb896c8a8a47a09e97892b3ee63441009 Mon Sep 17 00:00:00 2001 From: pmpknu Date: Mon, 28 Oct 2024 11:36:56 +0300 Subject: [PATCH 06/13] feat(p19): add configuration files - add .gitignore to not to commit trash - add .ocamlformat config - add dune-project main dune config - add p19.opam which is dune-project product - add dune with `zanuda` linter - add bin/dune with correct export of lib --- p19/.gitignore | 29 +++++++++++++++++++++++++++++ p19/.ocamlformat | 2 ++ p19/bin/dune | 4 ++++ p19/bin/main.ml | 1 + p19/dune | 6 ++++++ p19/dune-project | 22 ++++++++++++++++++++++ p19/p19.opam | 28 ++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+) create mode 100644 p19/.gitignore create mode 100644 p19/.ocamlformat create mode 100644 p19/bin/dune create mode 100644 p19/bin/main.ml create mode 100644 p19/dune create mode 100644 p19/dune-project create mode 100644 p19/p19.opam diff --git a/p19/.gitignore b/p19/.gitignore new file mode 100644 index 0000000..d4b6695 --- /dev/null +++ b/p19/.gitignore @@ -0,0 +1,29 @@ +*.annot +*.cmo +*.cma +*.cmi +*.a +*.o +*.cmx +*.cmxs +*.cmxa + +# ocamlbuild working directory +_build/ + +# ocamlbuild targets +*.byte +*.native + +# oasis generated files +setup.data +setup.log + +# Merlin configuring file for Vim and Emacs +.merlin + +# Dune generated files +*.install + +# Local OPAM switch +_opam/ \ No newline at end of file diff --git a/p19/.ocamlformat b/p19/.ocamlformat new file mode 100644 index 0000000..a1f73b2 --- /dev/null +++ b/p19/.ocamlformat @@ -0,0 +1,2 @@ +profile = janestreet +version = 0.26.2 \ No newline at end of file diff --git a/p19/bin/dune b/p19/bin/dune new file mode 100644 index 0000000..23f8aa2 --- /dev/null +++ b/p19/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name p19) + (name main) + (libraries p19_lib)) diff --git a/p19/bin/main.ml b/p19/bin/main.ml new file mode 100644 index 0000000..7bf6048 --- /dev/null +++ b/p19/bin/main.ml @@ -0,0 +1 @@ +let () = print_endline "Hello, World!" diff --git a/p19/dune b/p19/dune new file mode 100644 index 0000000..382dae6 --- /dev/null +++ b/p19/dune @@ -0,0 +1,6 @@ +(rule + (alias lint) + (action + (progn + (echo "Running zanuda on OCaml files...") + (run bash -c "zanuda lib/*.ml")))) \ No newline at end of file diff --git a/p19/dune-project b/p19/dune-project new file mode 100644 index 0000000..b34488f --- /dev/null +++ b/p19/dune-project @@ -0,0 +1,22 @@ +(lang dune 3.16) + +(name p19) + +(generate_opam_files true) + +(source + (github pmpknu/fp-lab1)) + +(authors "Dan Gorlyakov") + + +(license MIT) + +; (documentation https://url/to/documentation) + +(package + (name p19) + (synopsis "fp lab1") + (description "two tasks for the first lab for fp course at itmo") + (depends ocaml dune) +) \ No newline at end of file diff --git a/p19/p19.opam b/p19/p19.opam new file mode 100644 index 0000000..b7bf127 --- /dev/null +++ b/p19/p19.opam @@ -0,0 +1,28 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "fp lab1" +description: "two tasks for the first lab for fp course at itmo" +authors: ["Dan Gorlyakov"] +license: "MIT" +homepage: "https://github.com/pmpknu/fp-lab1" +bug-reports: "https://github.com/pmpknu/fp-lab1/issues" +depends: [ + "ocaml" + "dune" {>= "3.16"} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/pmpknu/fp-lab1.git" From 818a9a1faf83b0227e48dc27e84dae28be18283d Mon Sep 17 00:00:00 2001 From: pmpknu Date: Mon, 28 Oct 2024 13:19:19 +0300 Subject: [PATCH 07/13] feat(p19): add recursive solution implementation --- p19/lib/rec.ml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 p19/lib/rec.ml diff --git a/p19/lib/rec.ml b/p19/lib/rec.ml new file mode 100644 index 0000000..9f8d653 --- /dev/null +++ b/p19/lib/rec.ml @@ -0,0 +1,13 @@ +open Date + +let rec count_sundays year month day_of_week = + if year > 2000 then 0 + else + let new_count = if day_of_week = 0 then 1 else 0 in + let days_this_month = days_in_month year month in + let next_day_of_week = (day_of_week + days_this_month) mod 7 in + if month == 12 then + new_count + count_sundays (year + 1) 1 next_day_of_week + else + new_count + count_sundays year (month + 1) next_day_of_week + From 399539ab7301d7e2bc12c9e3c2ce3b15391539bb Mon Sep 17 00:00:00 2001 From: pmpknu Date: Mon, 28 Oct 2024 13:20:15 +0300 Subject: [PATCH 08/13] typo(p19): apply ocamlformat --- p19/dune | 2 +- p19/lib/date.ml | 6 +++--- p19/lib/rec.ml | 14 +++++++------- p19/lib/tailrec.ml | 13 +++++++------ 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/p19/dune b/p19/dune index 382dae6..a7634fa 100644 --- a/p19/dune +++ b/p19/dune @@ -3,4 +3,4 @@ (action (progn (echo "Running zanuda on OCaml files...") - (run bash -c "zanuda lib/*.ml")))) \ No newline at end of file + (run bash -c "zanuda lib/*.ml")))) diff --git a/p19/lib/date.ml b/p19/lib/date.ml index f8ea242..1d329ef 100644 --- a/p19/lib/date.ml +++ b/p19/lib/date.ml @@ -1,9 +1,9 @@ -let is_leap year = - (year mod 4 = 0 && year mod 100 <> 0) || (year mod 400 = 0) +let is_leap year = (year mod 4 = 0 && year mod 100 <> 0) || year mod 400 = 0 let days_in_month year month = match month with | 1 | 3 | 5 | 7 | 8 | 10 | 12 -> 31 | 4 | 6 | 9 | 11 -> 30 | 2 -> if is_leap year then 29 else 28 - | _ -> failwith "Invalid month" \ No newline at end of file + | _ -> failwith "Invalid month" +;; diff --git a/p19/lib/rec.ml b/p19/lib/rec.ml index 9f8d653..1e7f8cf 100644 --- a/p19/lib/rec.ml +++ b/p19/lib/rec.ml @@ -1,13 +1,13 @@ open Date let rec count_sundays year month day_of_week = - if year > 2000 then 0 - else + if year > 2000 + then 0 + else ( let new_count = if day_of_week = 0 then 1 else 0 in let days_this_month = days_in_month year month in let next_day_of_week = (day_of_week + days_this_month) mod 7 in - if month == 12 then - new_count + count_sundays (year + 1) 1 next_day_of_week - else - new_count + count_sundays year (month + 1) next_day_of_week - + if month == 12 + then new_count + count_sundays (year + 1) 1 next_day_of_week + else new_count + count_sundays year (month + 1) next_day_of_week) +;; diff --git a/p19/lib/tailrec.ml b/p19/lib/tailrec.ml index 6d98313..4190a6f 100644 --- a/p19/lib/tailrec.ml +++ b/p19/lib/tailrec.ml @@ -1,12 +1,13 @@ open Date let rec count_sundays year month day_of_week count = - if year > 2000 then count - else + if year > 2000 + then count + else ( let new_count = if day_of_week = 0 then count + 1 else count in let days_this_month = days_in_month year month in let next_day_of_week = (day_of_week + days_this_month) mod 7 in - if month == 12 then - count_sundays (year + 1) 1 next_day_of_week new_count - else - count_sundays year (month + 1) next_day_of_week new_count + if month == 12 + then count_sundays (year + 1) 1 next_day_of_week new_count + else count_sundays year (month + 1) next_day_of_week new_count) +;; From 9d4bdb3b80d5ce8717afc06d9bd0a3ac3f5120c6 Mon Sep 17 00:00:00 2001 From: pmpknu Date: Mon, 28 Oct 2024 15:36:20 +0300 Subject: [PATCH 09/13] feat(p19): add module implementation - use zellers congruence algorithm - use filter to get months with Sunday as a firsth day - use fold to get an answer --- p19/lib/module.ml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 p19/lib/module.ml diff --git a/p19/lib/module.ml b/p19/lib/module.ml new file mode 100644 index 0000000..3d8c877 --- /dev/null +++ b/p19/lib/module.ml @@ -0,0 +1,19 @@ +let zellers_congruence year month day = + let (year, month) = + if month < 3 then (year - 1, month + 12) else (year, month) + in + let k = year mod 100 in + let j = year / 100 in + let f = day + (13 * (month + 1)) / 5 + k + k / 4 + j / 4 - (2 * j) in + (f mod 7 + 7) mod 7 + +let count_sundays start_year end_year = + let years = List.init (end_year - start_year + 1) (fun i -> start_year + i) in + let aux year = + let months = List.init 12 (fun m -> m + 1) in + List.filter (fun month -> zellers_congruence year month 1 = 0) months + |> List.length + in + List.fold_left (fun acc year -> + acc + aux year + ) 0 years \ No newline at end of file From a0dc658aae4ba5915f99dcb755ee11b77bcd5ade Mon Sep 17 00:00:00 2001 From: pmpknu Date: Tue, 29 Oct 2024 10:38:09 +0300 Subject: [PATCH 10/13] refactor(p19): move zellers congruence function to date module --- p19/lib/date.ml | 8 ++++++++ p19/lib/date.mli | 1 + p19/lib/map.ml | 11 +++++++++++ p19/lib/module.ml | 17 ++++------------- 4 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 p19/lib/map.ml diff --git a/p19/lib/date.ml b/p19/lib/date.ml index 1d329ef..a10af8a 100644 --- a/p19/lib/date.ml +++ b/p19/lib/date.ml @@ -7,3 +7,11 @@ let days_in_month year month = | 2 -> if is_leap year then 29 else 28 | _ -> failwith "Invalid month" ;; + +let zellers_congruence year month day = + let year, month = if month < 3 then year - 1, month + 12 else year, month in + let k = year mod 100 in + let j = year / 100 in + let f = day + (13 * (month + 1) / 5) + k + (k / 4) + (j / 4) - (2 * j) in + ((f mod 7) + 7) mod 7 +;; diff --git a/p19/lib/date.mli b/p19/lib/date.mli index ba35e56..4d6f036 100644 --- a/p19/lib/date.mli +++ b/p19/lib/date.mli @@ -1 +1,2 @@ val days_in_month : int -> int -> int +val zellers_congruence : int -> int -> int -> int diff --git a/p19/lib/map.ml b/p19/lib/map.ml new file mode 100644 index 0000000..e18fc9f --- /dev/null +++ b/p19/lib/map.ml @@ -0,0 +1,11 @@ +open Date + +let count_sundays start_year end_year = + let years = List.init (end_year - start_year + 1) (fun i -> start_year + i) in + let aux year = + let months = List.init 12 (fun m -> m + 1) in + let map_filter month = if zellers_congruence year month 1 = 0 then 1 else 0 in + List.fold_left ( + ) 0 (List.map map_filter months) + in + List.fold_left (fun acc year -> acc + aux year) 0 years +;; diff --git a/p19/lib/module.ml b/p19/lib/module.ml index 3d8c877..7e3859b 100644 --- a/p19/lib/module.ml +++ b/p19/lib/module.ml @@ -1,19 +1,10 @@ -let zellers_congruence year month day = - let (year, month) = - if month < 3 then (year - 1, month + 12) else (year, month) - in - let k = year mod 100 in - let j = year / 100 in - let f = day + (13 * (month + 1)) / 5 + k + k / 4 + j / 4 - (2 * j) in - (f mod 7 + 7) mod 7 +open Date let count_sundays start_year end_year = let years = List.init (end_year - start_year + 1) (fun i -> start_year + i) in let aux year = let months = List.init 12 (fun m -> m + 1) in - List.filter (fun month -> zellers_congruence year month 1 = 0) months - |> List.length + List.filter (fun month -> zellers_congruence year month 1 = 0) months |> List.length in - List.fold_left (fun acc year -> - acc + aux year - ) 0 years \ No newline at end of file + List.fold_left (fun acc year -> acc + aux year) 0 years +;; From 7aa611fddfd65ae57142758d00608fb3fe91cc9e Mon Sep 17 00:00:00 2001 From: pmpknu Date: Tue, 29 Oct 2024 10:42:03 +0300 Subject: [PATCH 11/13] feat(p19): add iterative solution implementation --- p19/lib/iterative.ml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 p19/lib/iterative.ml diff --git a/p19/lib/iterative.ml b/p19/lib/iterative.ml new file mode 100644 index 0000000..19cf1b9 --- /dev/null +++ b/p19/lib/iterative.ml @@ -0,0 +1,11 @@ +open Date + +let count_sundays start_year end_year = + let count = ref 0 in + for year = start_year to end_year do + for month = 1 to 12 do + if zellers_congruence year month 1 = 0 then incr count + done + done; + !count +;; From 31a7aa93f9a2ce7bc083be843ce92732a170917a Mon Sep 17 00:00:00 2001 From: pmpknu Date: Tue, 29 Oct 2024 11:06:09 +0300 Subject: [PATCH 12/13] fix(p19): fix some misses - add last of modules to main dune config - apply `dune fmt` --- p19/lib/dune | 2 +- p19/lib/iterative.ml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/p19/lib/dune b/p19/lib/dune index 75f9e0a..b2dd897 100644 --- a/p19/lib/dune +++ b/p19/lib/dune @@ -1,3 +1,3 @@ (library (name p19_lib) - (modules date tailrec)) + (modules date tailrec rec map iterative module)) diff --git a/p19/lib/iterative.ml b/p19/lib/iterative.ml index 19cf1b9..38dc1ca 100644 --- a/p19/lib/iterative.ml +++ b/p19/lib/iterative.ml @@ -7,5 +7,5 @@ let count_sundays start_year end_year = if zellers_congruence year month 1 = 0 then incr count done done; - !count + !count ;; From cd9492785873f8f843cf393273fb34da63ebd77e Mon Sep 17 00:00:00 2001 From: pmpknu Date: Tue, 29 Oct 2024 11:54:27 +0300 Subject: [PATCH 13/13] test(p19): add tests - test iterative, map, module, rec and tailrec - test data module --- p19/lib/date.ml | 15 +++++++++++++++ p19/lib/dune | 6 +++++- p19/lib/iterative.ml | 2 ++ p19/lib/map.ml | 2 ++ p19/lib/module.ml | 2 ++ p19/lib/rec.ml | 2 ++ p19/lib/tailrec.ml | 2 ++ 7 files changed, 30 insertions(+), 1 deletion(-) diff --git a/p19/lib/date.ml b/p19/lib/date.ml index a10af8a..e0ccd19 100644 --- a/p19/lib/date.ml +++ b/p19/lib/date.ml @@ -1,5 +1,10 @@ let is_leap year = (year mod 4 = 0 && year mod 100 <> 0) || year mod 400 = 0 +let%test "is_leap for leap year 2000" = is_leap 2000 = true +let%test "is_leap for leap year 2020" = is_leap 2020 = true +let%test "is_leap for non-leap year 1900" = is_leap 1900 = false +let%test "is_leap for non-leap year 2023" = is_leap 2023 = false + let days_in_month year month = match month with | 1 | 3 | 5 | 7 | 8 | 10 | 12 -> 31 @@ -8,6 +13,11 @@ let days_in_month year month = | _ -> failwith "Invalid month" ;; +let%test "days_in_month for February in leap year" = days_in_month 2020 2 = 29 +let%test "days_in_month for February in non-leap year" = days_in_month 2021 2 = 28 +let%test "days_in_month for January" = days_in_month 2021 1 = 31 +let%test "days_in_month for April" = days_in_month 2021 4 = 30 + let zellers_congruence year month day = let year, month = if month < 3 then year - 1, month + 12 else year, month in let k = year mod 100 in @@ -15,3 +25,8 @@ let zellers_congruence year month day = let f = day + (13 * (month + 1) / 5) + k + (k / 4) + (j / 4) - (2 * j) in ((f mod 7) + 7) mod 7 ;; + +let%test "zellers_congruence for 1 Jan 1900 (Monday)" = zellers_congruence 1900 1 1 = 2 +let%test "zellers_congruence for 1 Jan 2000 (Saturday)" = zellers_congruence 2000 1 1 = 0 +let%test "zellers_congruence for 1 Mar 2021 (Monday)" = zellers_congruence 2021 2 28 = 1 +let%test "zellers_congruence for 31 Dec 1999 (Friday)" = zellers_congruence 1999 12 31 = 6 diff --git a/p19/lib/dune b/p19/lib/dune index b2dd897..a21146d 100644 --- a/p19/lib/dune +++ b/p19/lib/dune @@ -1,3 +1,7 @@ (library (name p19_lib) - (modules date tailrec rec map iterative module)) + (modules date tailrec rec map iterative module) + (inline_tests + (flags (-verbose))) + (preprocess + (pps ppx_inline_test))) \ No newline at end of file diff --git a/p19/lib/iterative.ml b/p19/lib/iterative.ml index 38dc1ca..17ae191 100644 --- a/p19/lib/iterative.ml +++ b/p19/lib/iterative.ml @@ -9,3 +9,5 @@ let count_sundays start_year end_year = done; !count ;; + +let%test _ = count_sundays 1901 2000 = 171 diff --git a/p19/lib/map.ml b/p19/lib/map.ml index e18fc9f..9021a93 100644 --- a/p19/lib/map.ml +++ b/p19/lib/map.ml @@ -9,3 +9,5 @@ let count_sundays start_year end_year = in List.fold_left (fun acc year -> acc + aux year) 0 years ;; + +let%test _ = count_sundays 1901 2000 = 171 diff --git a/p19/lib/module.ml b/p19/lib/module.ml index 7e3859b..81b7114 100644 --- a/p19/lib/module.ml +++ b/p19/lib/module.ml @@ -8,3 +8,5 @@ let count_sundays start_year end_year = in List.fold_left (fun acc year -> acc + aux year) 0 years ;; + +let%test _ = count_sundays 1901 2000 = 171 diff --git a/p19/lib/rec.ml b/p19/lib/rec.ml index 1e7f8cf..5c89109 100644 --- a/p19/lib/rec.ml +++ b/p19/lib/rec.ml @@ -11,3 +11,5 @@ let rec count_sundays year month day_of_week = then new_count + count_sundays (year + 1) 1 next_day_of_week else new_count + count_sundays year (month + 1) next_day_of_week) ;; + +let%test _ = count_sundays 1901 1 2 = 171 diff --git a/p19/lib/tailrec.ml b/p19/lib/tailrec.ml index 4190a6f..3c6895d 100644 --- a/p19/lib/tailrec.ml +++ b/p19/lib/tailrec.ml @@ -11,3 +11,5 @@ let rec count_sundays year month day_of_week count = then count_sundays (year + 1) 1 next_day_of_week new_count else count_sundays year (month + 1) next_day_of_week new_count) ;; + +let%test _ = count_sundays 1901 1 2 0 = 171