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.26 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.25 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.24 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.23 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.22 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.21 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.20 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.19 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.18 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.17 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.16 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.15 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.14 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.13 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.12 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.11 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.10 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.9 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.8 tracks/fsharp/exercises/atbash-cipher/Example.fs
trackler-2.1.0.7 tracks/fsharp/exercises/atbash-cipher/Example.fs