Last active
March 27, 2017 18:50
-
-
Save talyian/bdc10c7a77f4488aeb988ddcf943459a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Computer Language Benchmarks Game | |
// http://benchmarksgame.alioth.debian.org/ | |
// | |
// contributed by Reed Adams | |
// *reset* | |
open System | |
type Node = | |
| Branch of Node * Node | |
| Leaf | |
let rec GenNode depth = | |
if depth = 0 | |
then Leaf | |
else | |
let d = depth - 1 | |
Branch(GenNode d, GenNode d) | |
let inline GenTree depth = GenNode depth | |
let rec GetCheckSum = function | |
| Leaf -> 1 | |
| Branch(l, r) -> 1 + (GetCheckSum l) + (GetCheckSum r) | |
[<EntryPoint>] | |
let main argv = | |
let depth = if argv.Length > 0 | |
then Int32.Parse(argv.[0]) | |
else 20 | |
let min_depth = 4 | |
let max_depth = Math.Max(min_depth + 2, depth) | |
let stretch_depth = max_depth + 1 | |
GenTree stretch_depth | |
|> GetCheckSum | |
|> printfn "stretch tree of depth %i\t check: %i" stretch_depth | |
let long_lived_tree = GenTree max_depth | |
for cur_depth in min_depth ..2 ..max_depth do | |
let iterations = 1 <<< (max_depth - cur_depth + min_depth) | |
let mutable check = 0 | |
for i in 1 ..iterations do | |
check <- check + GetCheckSum (GenTree cur_depth) | |
printfn "%i\t trees of depth %i\t check: %i" iterations cur_depth check | |
long_lived_tree | |
|> GetCheckSum | |
|> printfn "long lived tree of depth %i\t check: %i" max_depth | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment