- モナド値を操作したりモナド値を返したりする関数
- ここではliftM, join, filterM, foldMを扱う
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
-- 問題 https://gist.github.com/fujiyan/483893d875ff7e350ef1 | |
-- 他の方々の解答 | |
-- https://gist.github.com/iseebi/8f3f7388313c1a6005f9 | |
-- https://gist.github.com/fujiyan/5378cb1f0f82c98a3775 | |
data Attack = Normal | Critical | Gira | Begirama deriving Show | |
data Warrior = Warrior { | |
attack :: Int | |
} deriving Show |
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
#!/usr/bin/env python | |
# vim:fileencoding=utf8 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import audioread as ar | |
def pcm2float(short_ndary): | |
float_ndary = np.array(short_ndary, dtype=np.float64) | |
return np.where(float_ndary > 0.0, float_ndary / 32767.0, float_ndary / 32768.0) |
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
import Control.Monad() | |
type Birds = Int | |
type Pole = (Birds, Birds) | |
landLeft :: Birds -> Pole -> Either String Pole | |
landLeft n (left, right) | |
| abs ((left + n) - right) < 4 = Right (left + n, right) | |
| otherwise = Left ("Last state: " ++ show (left + n, right)) |
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
-- Writerを返す2引数関数を用いたfoldMによる整数の畳込みを行うために、9より大きい数が表れた場合は9より小さい数が表れた場合とは異なるログを残すような関数を実装せよ | |
import Control.Monad.Writer | |
binSmallsWriter :: Int -> Int -> Writer [String] Int | |
binSmallsWriter acc x | |
| x > 9 = do | |
tell [show x ++ " too big, not added"] | |
return acc | |
| otherwise = do |
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
main = do | |
contents <- getContents | |
print (sum $ map (length . (filter ('@' ==))) $ lines $ contents) |
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
main = do | |
c <- getContents | |
print (length $ filter ('@' ==) c) |
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
main=getContents>>=print.length.filter('@'==) |
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
"""べき乗則を用いて複素行列の最大固有値を求める""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
seed=1 | |
ndim = 10 | |
np.random.seed=seed | |
A = np.random.randn(ndim,ndim)+1.j*np.random.randn(ndim,ndim) | |
x = np.random.randn(ndim) + 1.j*np.random.randn(ndim) | |
niter = 300 |
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
"""goertzel algorithm python implementation | |
https://en.wikipedia.org/wiki/Goertzel_algorithm | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def goertzel(xs, f, fs, N): | |
df = fs / N | |
k = int(f/df) |
OlderNewer