fork download
  1. data Nat = S Nat | Z deriving (Eq)
  2.  
  3. instance Ord Nat where
  4. Z <= n = True
  5. S n <= Z = False
  6. S n <= S m = n <= m
  7.  
  8. {-min (S n) (S m) = S (min n m)
  9.   min _ _ = Z-}
  10.  
  11. instance Enum Nat where
  12. fromEnum Z = 0
  13. fromEnum (S n) = fromEnum n + 1
  14.  
  15. data Tree = Empty | Node Integer Tree Tree
  16.  
  17. minHeight Empty = Z
  18. minHeight (Node _ l r) = S (min (minHeight l) (minHeight r))
  19.  
  20. tree = Node 0 tree (Node 1 tree Empty)
  21.  
  22. -- mt = minHeight tree
  23.  
  24. -- min via (<=):
  25. -- mt
  26. -- S (min mt (S (min mt Z)))
  27. -- S (min mt (S Z))
  28. -- S (if mt <= S Z then mt else S Z)
  29. -- S (if S (if mt <= S Z then mt else S Z) <= S Z then mt else S Z)
  30. -- S (if (if mt <= S Z then mt else S Z) <= Z then mt else S Z)
  31. -- S (if (if (S (if mt <= S Z then mt else S Z)) <= S Z then mt else S Z) <= Z then mt else S Z)
  32. -- S (if (if (if mt <= S Z then mt else S Z) <= Z then mt else SZ) <= Z then mt else S Z)
  33. -- again (if mt <= S Z then mt else S Z)
  34.  
  35. -- recursive min:
  36. -- mt
  37. -- S (min mt (S (min mt Z)))
  38. -- S (min mt (S Z))
  39. -- S (min (S (min mt (S Z))) (S Z))
  40. -- S (S (min (min mt (S Z)) Z))
  41. -- S (S (min (S ...) Z))
  42. -- S (S Z)
  43.  
  44. main = print $ fromEnum $ minHeight tree -- 2
Time limit exceeded #stdin #stdout 5s 525824KB
stdin
Standard input is empty
stdout
Standard output is empty