Sha256: 43f073c293956201caf6f9218199a3be053febe558ad0e630d72e63133ed0e46

Contents?: true

Size: 430 Bytes

Versions: 42

Compression:

Stored size: 430 Bytes

Contents

open Base

let to_sorted_list s = String.to_list s |> List.sort ~compare:Char.compare

let anagrams target candidates =
  let target_lc = String.lowercase target in
  let target_sorted = to_sorted_list target_lc in
  List.map ~f:(fun c -> (c, String.lowercase c)) candidates
  |> List.filter ~f:(fun (_, lc) ->
      List.equal ~equal:Char.equal (to_sorted_list lc) target_sorted && String.(lc <> target_lc))
  |> List.map ~f:fst

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/ocaml/exercises/anagram/example.ml
trackler-2.2.1.138 tracks/ocaml/exercises/anagram/example.ml