2009-02-03から1日間の記事一覧

Problem 188

Problem 188 - Project Euler これは前に解いた. import Number (factors) import Data.List (group) phi :: Integer -> Integer phi = product.map f.group.factors where f ps@(p:_) = let n = length ps in p^(n-1)*(p-1) towerMod :: Integral a => Int…

tex 表

セルの結合(横) \multicolumn{2}{|c|}{foo} セルの結合(縦) ただし\usepackage{multirow} が必要. \multirow{2}{*}{bar} \cline{2-3} などと一緒に使う. 太い水平線 \hline のかわりに \noalign{\hrule height 1pt} 記号結合(?) \begin{tabular}[tb…

Problem 191

Problem 191 - Project Euler 素直なDP. import Data.Map (Map,unionsWith,filterWithKey,mapKeysWith,fold,singleton) type State = (Int,Int) late,onTime,absent :: State -> State late (a,l) = (0,l+1) onTime (_,l) = (0,l) absent (a,l) = (a+1,l) da…

Problem 190

Problem 190 - Project Euler ラグランジュの未定乗数法を使うだけ. import Data.Ratio ((%)) p :: (Integral a, Integral b) => a -> b p m = floor.product $ [(2*n % (m+1))^n | n <- [1..m]] p190 :: (Integral a, Integral b) => a -> b p190 m = sum.…