Sha256: 5e7e3aec319bd628d0e654b2d0298ba18dc05acdee5a1227539b3713defe2e90
Contents?: true
Size: 893 Bytes
Versions: 262
Compression:
Stored size: 893 Bytes
Contents
module Atbash open System let rec mapMaybe f list = match list with | [] -> [] | x::xs -> match f x with | Some(a) -> a :: mapMaybe f xs | None -> mapMaybe f xs let stringFromChars (chars:char seq) = new String(chars |> Array.ofSeq) let chunksOfSize n xs = xs |> Seq.mapi(fun i x -> i / n, x) |> Seq.groupBy fst |> Seq.map (fun (_, g) -> Seq.map snd g) let mapLetter letter = if Char.IsDigit letter then (letter, letter) else (letter, (char)((int)'z' - (int)letter + (int)'a')) let lettersMap = ['a' .. 'z'] @ ['0'..'9'] |> List.map mapLetter |> Map.ofList let encodeLetter letter = Map.tryFind (Char.ToLower letter) lettersMap let encodeInChunks = String.concat " " << Seq.map stringFromChars << chunksOfSize 5 let encodeStr = encodeInChunks << mapMaybe encodeLetter let encode (str:string) = str |> List.ofSeq |> encodeStr
Version data entries
262 entries across 262 versions & 1 rubygems