tracks/ocaml/exercises/pangram/example.ml in trackler-2.2.1.110 vs tracks/ocaml/exercises/pangram/example.ml in trackler-2.2.1.111
- old
+ new
@@ -1,9 +1,18 @@
-open Core
+open Base
-let string_to_set s = Char.Set.of_list (String.to_list s)
+exception Finished of int
-let alphabet_set = string_to_set "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-
let is_pangram s =
- let normalize s = String.filter ~f:Char.is_alpha s |> String.uppercase in
- Set.equal alphabet_set (string_to_set @@ normalize s)
+ let alphabet_bits = (1 lsl 26) - 1 in
+ let update_bits return b ch =
+ let updated =
+ if Char.is_alpha ch
+ then b lor (1 lsl (Char.to_int (Char.uppercase ch) - Char.to_int 'A'))
+ else b in
+ if updated = alphabet_bits then return alphabet_bits else updated
+ in
+ let return s = raise (Finished s) in
+ try
+ String.fold s ~init:0 ~f:(update_bits return) = alphabet_bits
+ with
+ Finished s -> Int.(s = alphabet_bits)
\ No newline at end of file