Converted 1st of December into using batteries as well.

This commit is contained in:
Vidir Valberg Gudmundsson 2017-12-05 23:33:06 +01:00
parent 42599df098
commit f8b5ad80c9

12
dec1.ml
View file

@ -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 () =