From f8b5ad80c97e9b10965c2e4a139322c788956045 Mon Sep 17 00:00:00 2001 From: Vidir Valberg Gudmundsson Date: Tue, 5 Dec 2017 23:33:06 +0100 Subject: [PATCH] Converted 1st of December into using batteries as well. --- dec1.ml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/dec1.ml b/dec1.ml index 4f70268..73dcfd2 100644 --- a/dec1.ml +++ b/dec1.ml @@ -10,13 +10,13 @@ (*91212129 produces 9 because the only digit that matches the next one is the*) (*last digit, 9.*) -open Core +open Batteries -let char_to_int x = int_of_string (Char.to_string x) +let char_to_int x = int_of_string (Char.escaped x) let rec algo' (chars : char list) (first : int) (acc : int list) = match chars with - | [] -> List.fold_left ~f:(+) ~init:0 acc + | [] -> List.fold_left (+) 0 acc | c1 :: (c2 :: rest) -> if Char.equal c1 c2 then algo' (c2 :: rest) first (char_to_int c1 :: acc) @@ -29,9 +29,7 @@ let rec algo' (chars : char list) (first : int) (acc : int list) = let algo (chars : char list) = let - first = match List.hd chars with - | Some x -> x - | None -> '0' + first = List.hd chars in algo' chars (char_to_int first) [] @@ -40,7 +38,7 @@ let solve_captcha number = number |> String.to_list |> algo - |> printf "Passcode is: %d\n" + |> print_int let () =