Comment detail

LL Golf Hole 7 - バイト数を読みやすくする (Nested Flatten)

This comment is reply for 7327 nori: 前出の再帰バージョン。 再帰のありがた...(LL Golf Hole 7 - バイト数を読みやすくする). Go to thread root.

移植しました。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#load "nums.cma";;
open Num
let conv =
  let base = (Int 1024) in
  let rec sub byte k bound = function
    | [] -> raise (Invalid_argument "over")
    | hd::tl -> 
        if byte </ bound then
          Printf.sprintf "%.1f%s" (float_of_num (byte // k)) hd
        else
          sub byte (k */ base) (bound */ base) tl
  in
    fun byte -> sub byte (Int 1) base ["b"; "k"; "M"; "G";"T"]
  ;;
(*
  conv (Int 1024);;
  conv (Big_int (Big_int.big_int_of_string "10000000000"));; 
*)

Index

Feed

Other

Link

Pathtraq

loading...