Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- No optimization performed during compilation
- tnvOne :: Integer -> Bool
- tnvOne = aux 0 0
- where
- aux a c n
- | a == n = True
- | a > n = False
- | a < n = aux (a + c) (c + 1) n
- tnvTwo :: Integer -> Bool
- tnvTwo = aux 1
- where
- aux c n
- | n == 0 = True
- | n < 0 = False
- | n > 0 = aux (c + 1) (n - c)
- tnvThree :: Integer -> Bool
- tnvThree = aux 0
- where
- aux c n
- | n > tng c = aux (c + 1) n
- | n == tng c = True
- | n < tng c = False
- where
- tng x = x * (x + 1) `div` 2
- tnvFour :: (RealFrac t, Floating t) => t -> Bool
- tnvFour n = ceiling m == floor m
- where
- m = sqrt (n * 8 + 1)
- theNumber = 1000000000000
- main :: IO ()
- main = do
- -- print $ tnvOne theNumber
- -- total time = 0.59 secs (589 ticks @ 1000 us, 1 processor)
- -- print $ tnvTwo theNumber
- -- total time = 0.88 secs (883 ticks @ 1000 us, 1 processor)
- -- print $ tnvThree theNumber
- -- total time = 1.28 secs (1283 ticks @ 1000 us, 1 processor)
- -- print $ tnvFour theNumber
- -- total time = 0.00 secs (0 ticks @ 1000 us, 1 processor)
- return ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement