Skip to content

Instantly share code, notes, and snippets.

@jsakamoto
Created November 10, 2016 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsakamoto/13b0399f6599345460f053d1e0be3fa3 to your computer and use it in GitHub Desktop.
Save jsakamoto/13b0399f6599345460f053d1e0be3fa3 to your computer and use it in GitHub Desktop.
Learn F# - mastering “Seq.map” – decode to ASCII art
let code = "f8f8f8f8f7b2f8f63181f8f5c1318131f8f401318101f8f3c10131810131f8f202318102f8f1c10231810231f803718103f7c10211f1e10331f6810271f28103f5e10211f1b1f1e10331f40371c131f28103f3c10211f10131f2e10331f2810271e10131f38103f1e103f1810131f3c10371f1810211e10131f3810211f2e103f18131f2e10331f3810231e131f28103f4e103f1b1f1e10371f5810231f2810211f6e103f1e10331f7810231810211f8e10231810271f8f1810131810111f8f2e10131810131f8f381318111f8f4c1318171f8f53191f8f7b1f8f8f8f8f07"
let decodeIt (code:string) =
let data =
[0..(code.Length/2)-1]
|> Seq.map (fun n -> code.Substring(n*2, 2))
|> Seq.map (fun s -> new String(s.[0], Convert.ToInt32(string s.[1], 16)))
|> Seq.toArray |> (fun a -> String.Join ("", a))
[0..(data.Length/2)-1]
|> Seq.map (fun n -> (n, data.Substring(n*2, 2)))
|> Seq.map (fun (n,s) -> (n, Convert.ToByte(s, 16)))
|> Seq.map (fun (n,i) -> (n, Convert.ToString(i,2).PadLeft(8,'0')))
|> Seq.map (fun (n,s) -> (n, s.Replace('1', '*').Replace('0',' ')))
|> Seq.map (fun (n,s) -> (if(n % 8 = 7)then printfn else printf) "%s" s)
|> Seq.toArray |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment