-
-
Save keturiosakys/79817c68bdb70c3ffc43383928767e4e to your computer and use it in GitHub Desktop.
Given a string, separate it into groups of non-space equal characters, sorted.
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 Base | |
open Stdio | |
let explode_string str = | |
String.to_list str | |
|> List.filter ~f:(fun c -> not (phys_equal c ' ')) | |
|> List.sort_and_group ~compare:(fun a b -> Char.compare a b) | |
|> List.map ~f:(fun l -> String.of_char_list l) | |
let%expect_test "explode_string 1" = | |
let res = explode_string "Ahh, abracadabra!" in | |
List.iter res ~f:(fun str -> print_string str); | |
[%expect {|!,Aaaaaabbcdhhrr|}] | |
let%expect_test "explode_string 2" = | |
let res = explode_string "\\o/\\o/" in | |
List.iter res ~f:(fun str -> print_string str); | |
[%expect {|//\\oo|}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment