Skip to content

Instantly share code, notes, and snippets.

@Gab-km
Created December 15, 2015 08:28
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 Gab-km/021b68c5fc714ef341bc to your computer and use it in GitHub Desktop.
Save Gab-km/021b68c5fc714ef341bc to your computer and use it in GitHub Desktop.
何かのコード
module ConsolePrinter =
open System.Text
open System.ComponentModel
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private bit mask b =
b &&& mask = mask
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private bit0 = bit 0b00000001uy
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private bit1 = bit 0b00000010uy
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private bit2 = bit 0b00000100uy
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private bit3 = bit 0b00001000uy
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private bit4 = bit 0b00010000uy
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private bit5 = bit 0b00100000uy
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private bit6 = bit 0b01000000uy
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private bit7 = bit 0b10000000uy
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private numToBits b = [
yield bit0 b
yield bit1 b
yield bit2 b
yield bit3 b
yield bit4 b
yield bit5 b
yield bit6 b
yield bit7 b
]
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private boolToAster b =
if b then "*" else " "
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private asterListToMultiLineStr (asts: string list) =
let rec astmls (asts: string list) (sb: StringBuilder) offset =
match asts with
| x::xs ->
sb.Append(x) |> ignore
if offset = 15 then
sb.Append("\n") |> ignore
astmls xs sb 0
else
astmls xs sb (offset+1)
| _ -> sb
astmls asts (System.Text.StringBuilder()) 0
|> fun sb -> sb.ToString()
[<EditorBrowsable(EditorBrowsableState.Never)>]
let private flatten xss = [
for xs in xss do
for x in xs do
yield x
]
let printPicture =
List.map numToBits
>> flatten
>> List.map boolToAster
>> asterListToMultiLineStr
>> printfn "%s"
let data = [
0xE0uy; 0x03uy; 0xF0uy; 0x0Fuy; 0xF0uy; 0x03uy; 0xF8uy; 0x0Fuy
0xF8uy; 0x1Fuy; 0xF8uy; 0x0Fuy; 0xE0uy; 0x07uy; 0xF0uy; 0x01uy
0xF8uy; 0x0Fuy; 0xFCuy; 0x3Fuy; 0xFCuy; 0x3Fuy; 0xFCuy; 0x3Fuy
0xFCuy; 0x3Fuy; 0x70uy; 0x0Euy; 0x38uy; 0x1Cuy; 0x3Cuy; 0x3Cuy
]
[<EntryPoint>]
let main argv =
ConsolePrinter.printPicture data
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment