Permalink
Browse files

Refactoring solution 1 in OCaml.

  • Loading branch information...
1 parent 7083a93 commit d4c59512afa672d0ded7a6b760f2e432e1e1f8f7 Siraaj Khandkar committed Apr 12, 2012
Showing with 8 additions and 12 deletions.
  1. +8 −12 001/solution_001.ml
View
@@ -1,18 +1,14 @@
-let rec project_euler_001 n acc =
- match n with
- 0 -> acc
- | n ->
- match (n mod 3 == 0) || (n mod 5 == 0) with
- true ->
- project_euler_001 (n - 1) (n + acc)
- | false ->
- project_euler_001 (n - 1) (acc)
+let rec sum_of_mults_of_3n5 = function
+ | (0, sum) -> sum
+ | (n, sum) ->
+ match (n mod 3 == 0) || (n mod 5 == 0) with
+ | true -> sum_of_mults_of_3n5 ((n - 1), (n + sum))
+ | false -> sum_of_mults_of_3n5 ((n - 1), (sum))
let project_euler_001 n =
- let solution = project_euler_001 (n - 1) 0 in
- print_int solution;
- print_endline ""
+ let solution = sum_of_mults_of_3n5 ((n - 1), 0) in
+ print_newline (print_int solution)
let () = project_euler_001 1000

0 comments on commit d4c5951

Please sign in to comment.