Skip to content

Instantly share code, notes, and snippets.

@frectonz
Last active May 29, 2023 10:12
Show Gist options
  • Save frectonz/d61bc387867177dae85302237966842b to your computer and use it in GitHub Desktop.
Save frectonz/d61bc387867177dae85302237966842b to your computer and use it in GitHub Desktop.
From cassidoo's May 29, 2023 Newsletter
module KeyToRowMap = Map.Make (Char)
let qwertyKeyToRowMap =
let firstRow = ['q'; 'w'; 'e'; 'r'; 't'; 'y'; 'u'; 'i'; 'o'; 'p'] in
let secondRow = ['a'; 's'; 'd'; 'f'; 'g'; 'h'; 'j'; 'k'; 'l'] in
let thirdRow = ['z'; 'x'; 'c'; 'v'; 'b'; 'n'; 'm'] in
KeyToRowMap.empty
|> (fun m -> List.fold_left (fun acc key -> KeyToRowMap.add key 1 acc) m firstRow)
|> (fun m -> List.fold_left (fun acc key -> KeyToRowMap.add key 2 acc) m secondRow)
|> (fun m -> List.fold_left (fun acc key -> KeyToRowMap.add key 3 acc) m thirdRow)
let isWordInOneRow map word =
let word = String.lowercase_ascii word in
let firstCharRow = KeyToRowMap.find word.[0] map in
word
|> String.for_all (fun c -> KeyToRowMap.find c map == firstCharRow)
let oneRow = List.filter (isWordInOneRow qwertyKeyToRowMap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment