Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main where
- import Data.Time.Clock.POSIX
- import System.IO
- main :: IO ()
- main = do
- putStrLn "Tap to the beat of a song to determine its BPM."
- hSetEcho stdin False
- hSetBuffering stdin NoBuffering
- loop [1]
- average :: (Foldable t, Integral a) => t a -> a
- average n = sum n `div` fromIntegral (length n)
- takeLast :: Int -> [t] -> [t]
- takeLast n [] = []
- takeLast n l = drop (length l - n) l
- diff :: Num t => [t] -> [t]
- diff [] = []
- diff ls = zipWith (-) (tail ls) ls
- loop :: [Integer] -> IO a
- loop lst = do
- getChar
- t <- getPOSIXTime
- let lastFew = takeLast 4 lst ++ [round (t * 1000)]
- print (60000 `div` average (diff lastFew))
- loop lastFew
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement