-
-
Save keturiosakys/59966046f0f74f30982cff877e2bd46e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core | |
let all_letters = | |
let all = "abcdefghijklmnopqrstuvwxyz" in | |
List.init (String.length all) ~f:(String.get all) | |
let missing_letters (letters : char list) = | |
let start_pos, end_pos = | |
( List.findi all_letters ~f:(fun _ letter -> | |
Char.compare letter (List.hd_exn letters) = 0) | |
|> Option.value_exn |> fst, | |
List.findi all_letters ~f:(fun _ letter -> | |
Char.compare letter (List.last_exn letters) = 0) | |
|> Option.value_exn |> fst ) | |
in | |
let slice = List.slice all_letters start_pos end_pos in | |
List.filter slice ~f:(fun letter -> | |
not | |
(List.find letters ~f:(fun l -> Char.compare l letter = 0) | |
|> Option.is_some)) | |
let%test_module "missing_letters" = | |
(module struct | |
let%test_unit "test 1" = | |
[%test_eq: char list] | |
(missing_letters [ 'a'; 'b'; 'c'; 'd'; 'f' ]) | |
[ 'e' ] | |
let%test_unit "test 2" = | |
[%test_eq: char list] | |
(missing_letters | |
[ | |
'a'; | |
'b'; | |
'c'; | |
'd'; | |
'e'; | |
'h'; | |
'i'; | |
'j'; | |
'k'; | |
'l'; | |
'm'; | |
'n'; | |
'o'; | |
'p'; | |
'q'; | |
'r'; | |
's'; | |
't'; | |
'u'; | |
'w'; | |
'x'; | |
'y'; | |
'z'; | |
]) | |
[ 'f'; 'g'; 'v' ] | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment