Skip to content

Instantly share code, notes, and snippets.

@ksauzz
Created September 5, 2011 11:25
Show Gist options
  • Save ksauzz/1194734 to your computer and use it in GitHub Desktop.
Save ksauzz/1194734 to your computer and use it in GitHub Desktop.
第一回スタートhaskell 宿題
-- Start Haskell 01 -- Homework : http://groups.google.com/group/start-haskell/browse_thread/thread/57aeccfd1073ca6
-- problem 1
magComp :: Float -- 地震1のマグニチュード
-> Float -- 地震2のマグニチュード
-> Float -- 地震1が何倍強い
magComp x y = (magCulc x) / (magCulc y)
magCulc :: Float -> Float
magCulc m = 10 ** (4.8 + 1.5 * m)
-- problem 2-1
approxEq :: Float -- Δ
-> Float -- 値1
-> Float -- 値2
-> Bool -- 値2 ∈ (値1 - Δ, 値1 + Δ)
approxEq a x1 x2 | x1 - a < x2 && x2 < x1 + a = True
| otherwise = False
-- problem 2-2
approxEq' :: Float -- 値1
-> Float -- 値2
-> Bool -- 値2 ∈ (値1 - 0.0001, 値1 + 0.0001)
approxEq' = approxEq 0.0001
-- problem 2-3
approxZero :: Float -- 値
-> Bool -- 値 ∈ (-0.0001, 0.0001)
approxZero = approxEq' 0
-- problem 3
compLevel :: (Int, Int) -- 幅(ピクセル), 高さ(ピクセル)
-> Float -- フレームレート(フレーム/秒)
-> Int -- 時間(秒)
-> Float -- オーディオ・ビットレート(Kb/秒)
-> Float -- ファイルサイズ(MiB)
-> Float -- 画像圧縮率
compLevel (width, height) frameRate sec audioBitRate fileSize
= (imageFileSize + audioFileSize) * fromIntegral sec / flatFileSize
where
imageFileSize = fromIntegral width * fromIntegral height * frameRate * 24::Float -- bit/s
audioFileSize = audioBitRate * 1000::Float -- bit/s
flatFileSize = fileSize * 1024 * 1024 * 8 -- bit/s
-- problem 4
compLevel :: (Int, Int) -- 幅(ピクセル), 高さ(ピクセル)
revmid :: [a] -> [a]
revmid [] = []
revmid [x, y] = [x, y]
revmid xs = [h] ++ rmid ++ [t]
where
h = head xs
rmid = tail(reverse(tail(xs)))
t = head(reverse(xs))
@ksauzz
Copy link
Author

ksauzz commented Sep 5, 2011

なんか誤差が出る…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment