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.1.0.6 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.5 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.4 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.3 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.2 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.1 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.0 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.55 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.54 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.53 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.52 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.51 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.50 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.49 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.48 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.47 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.46 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.45 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.44 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.0.8.43 tracks/fsharp/exercises/atbash-cipher/Example.fs