Skip to content

Instantly share code, notes, and snippets.

@callmekohei
Last active November 8, 2016 07:21
Show Gist options
  • Save callmekohei/ffc685e9e7bce566da7086586c68e110 to your computer and use it in GitHub Desktop.
Save callmekohei/ffc685e9e7bce566da7086586c68e110 to your computer and use it in GitHub Desktop.
let inline prettyPrint (row : int ) (space : string) (lst: 'a list) =
let swapRowColumn lst =
lst
|> List.collect List.indexed
|> List.groupBy fst
|> List.map snd
|> List.map (List.map snd)
let sjis = System.Text.Encoding.GetEncoding "Shift_JIS"
let justify lst =
let lst = lst|> List.map ( fun x -> string x , sjis.GetByteCount (string x) )
let max =
lst
|> List.map snd
|> List.max
List.map (fun (str, len) -> str + String.replicate (max - len) " ") lst
lst
|> List.chunkBySize row
|> swapRowColumn
|> List.map justify
|> List.map ( List.reduce ( fun a b -> a + space + b ))
|> List.iter ( fun l -> printfn "%s" l )
@callmekohei
Copy link
Author

['a'..'z'] |> prettyPrint 3 "\t"
a	d	g	j	m	p	s	v	y
b	e	h	k	n	q	t	w	z
c	f	i	l	o	r	u	x

.

[1..30] |> prettyPrint 3 "\t"
1 	4 	7 	10	13	16	19	22	25	28
2 	5 	8 	11	14	17	20	23	26	29
3 	6 	9 	12	15	18	21	24	27	30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment