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

Version Path
trackler-2.2.1.44 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.43 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.42 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.41 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.40 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.39 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.38 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.37 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.36 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.35 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.34 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.33 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.32 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.31 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.30 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.29 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.28 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.27 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.26 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.2.1.25 tracks/fsharp/exercises/atbash-cipher/Example.fs