2008-11-01ãã1ã¶æéã®è¨äºä¸è¦§
大æ¹ã®äºæ³ãè£åããè¦äºå®èµ°ã§ãã¾ãããã»ãã¨ãããããã§ãã
http://projecteuler.net/index.php?section=problems&id=117 ãã®ã¾ã¾ï¼¤ï¼°ã import Data.Array.IArray measure n = mArr!n where mArr = listArray (0,n). map m $[0..n]::Array Int Integer m 0 = 1 m x = sum.map m'.zipWith (-) (repeat x) $ [1..4] m'â¦
åéã¨åããããªèãæ¹ãããããã£ã¡ã®ã»ããç°¡åã ã¨æãã choose n r = div (product [n-r+1..n]) $ product [1..r] replace m n = sum[choose (n+t-t*m) t | t<-[1..div n m]] main = print.sum.zipWith replace [2,3,4] $ repeat 50
m=3ã®ã¨ãred(5)black(2)red(3) (n=10)ã次ã®ããã«èãã â âââ¡ââ (â¡)black(3)red(3)black(1)red(6)black(1) (n=14)ãªãã° ââââ â¡â ââââ¡(â)âï¼ç´åã¨åãè²ï¼å é ãªãblackï¼ â ï¼red ã®ã¯ãã¾ãï¼â (3=m)åã¶ãï¼ â¡ï¼black ã®ã¯ãã¾ã (ç´åã red ã®çµãã) æâ¦
http://projecteuler.net/index.php?section=problems&id=114 æ®éã®DP import Data.Array.IArray measure n = mArr!n where mArr = listArray (0,n). map m $ [0..n]::Array Int Integer m n | n < 3 = 1 | n == 3 = 2 | n > 3 = sum [mArr!(n-m-1)| m<-0:[â¦
http://projecteuler.net/index.php?section=problems&id=113ã¨ãããããå帰å¼ãèãã¦ãDPã«ããã ããããããªãããããªå帰å¼ãªã®ã§æè¨ç®ã§ãããã§ã¯ããããããããã import Data.Array.IArray n = 100 mkArray :: (Ix i)=> (i -> Integer)-> (iâ¦
http://projecteuler.net/index.php?section=problems&id=112 ãã¤ã¼ããªå®è£ ãé ããªãã®ã§ãããã¨ããã map2 f xs = zipWith f xs $ tail xs descend, ascend :: Integer -> Bool descend = and.map2 (>=).show ascend = and.map2 (<=).show main = prinâ¦
ä»æ¥ãã¤ãã¼ã¨ã¼ã«ãã¼ã§é´ä¸è²·ã£ããã éå ã»ã¼ã«ä¸ã§1å²è¿ã£ã¦ããããªããã¡ãã£ã¨ããããã£ãã éé¡ã¯100ããããªãã ãã©ãå¤§å ¥è¢ã«å ¥ã£ã¦è¿ã£ã¦ããããªãããä¸æ³ããããã©ãããã¨é¢ä¿ããã®ããï¼
http://projecteuler.net/index.php?section=problems&id=120ç°¡åãªè¨ç®ï¼ã¨ããããæå¤ã¨æéãããã£ãã®ã¯å ç·ã ï¼ã§ a:even -> a*(a-2) a:odd -> a*(a-1) ãåããããããåããã°ãå¾ã¯ç°¡åã rMax a | even a = a*(a-2) | odd a = a*(a-1) main = prâ¦
http://projecteuler.net/index.php?section=problems&id=118ããã£ã¦æ®éã®è§£æ³ã ã¨æãã import Data.List import Number permPrime :: [Char] -> Integer permPrime = genericLength.filter isPrime'.map read.permutations comb _ 0 = [[]] comb [] _ =â¦
ghc --make foo.hs -prof ./foo.exe +RTS -hc hp2ps foo.hp (fiber foo.ps)ã§ãªããå¤ãªpsãã¡ã¤ã«ãã§ããã ã¿ãããè¯ãåãããªãããã©ãããã¡ã¢ãªæ¶è²»éã®ãããªãã®ã表ãã¦ããããã ãåèï¼ http://itpro.nikkeibp.co.jp/article/COLUMN/20070403â¦
http://projecteuler.net/index.php?section=problems&id=111æ®éã®è§£æ³ãåãæ°ãå¤ãé£ç¶æ°ããä½ã£ã¦ãç´ æ°ããã§ãã¯ã import Number import Data.Char import Data.List toInt = read.map intToDigit :: [Int]->Integer repDigit (d+1) m (n+1) = [k:xâ¦
http://projecteuler.net/index.php?section=problems&id=109ã¨ãããããå帰ã§æ¸ãã¦ãDPã«ãªãããã¨æã£ãã import Data.List score = sort$[1..20]++map (2*) [1..20]++map (3*) [1..20]++[25,50] double = map (2*) $ [1..20]++[25] finish0 n = map â¦
import Number import Data.List import Data.Maybe dscList lim max' | lim < 1 = [[]] | otherwise = [x:ys|x<-[1..max'],ys<-dscList (lim' x) x] where lim' y = lim / (2*(fromIntegral y)+1) p110 = dscList 7999999 60 decode = product.zipWith (^) â¦
http://projecteuler.net/index.php?section=problems&id=1081/a+1/b=1/nã§ãããb=n+b'ã¨æ¸ãæãã㨠n^2ãb'ã§å²ãåãããã¨ãåããã å¾ã£ã¦ãn^2ã1999åã®ç´æ°ãæã¤æå°ã®nãæ¢ãã°ããã import Number import Data.List import Data.Maybe descenâ¦
http://projecteuler.net/index.php?section=problems&id=106ã¨ããããåé¡æãç解ããã®ã«ãããæéãããã£ãã ãªãã§ãn=4ã§25ã«ãªãã®ãåãããªãã£ãã ã¨ããããåå 㯠åé¡æãã©ãã¾ã§ãªã¹ãã®è¦ç´ ãæé ã§ããä»®å®ãã¤ãã£ã¦ããã®ã æè¨ãâ¦
http://projecteuler.net/index.php?section=problems&id=105ã¡ãã£ã¨èããããã·ã³ãã«ãªè§£æ³ã«æ°ãã¤ããã import Data.List monotone xs = all (f.sort$xs) [1..length xs `div` 2] where f ys n = (sum.take (n+1)) ys > (sum.take n.reverse) ys subsâ¦
http://projecteuler.net/index.php?section=problems&id=104åç´ãªè§£æ³ import Data.List fib = 0:1:zipWith (+) fib (tail fib) fibMod = map (flip mod (10^9))$0:1:zipWith (+) fibMod (tail fibMod) main = print.findIndex pandigit.zip fibMod $fib wâ¦
http://projecteuler.net/index.php?section=problems&id=107ã©ãã¿ã¦ãæå°æ¨åé¡ã§ããæ¬å½ã«(ryã¨ããããã§ãä»åã¯ã©ã¤ãã©ãªã使ã£ã¦ã¿ãã ãªãã¨ãæå°æ¨ãæ±ããé¢æ°ãããã¨ããå å®ã¶ãã import Data.List import Data.Array import Data.Graph.â¦
http://projecteuler.net/index.php?section=problems&id=102ä¸è§å½¢ã®å é¨å¤å®ã å¤ç©ã使ãã¨æ¥½ãããªã import Data.List cross (x,y) (u,v) = x*v-y*u containO [x,y,z] = sameSign.map (uncurry cross)$[(x,y),(y,z),(z,x)] where sameSign xs = all (>0â¦
http://projecteuler.net/index.php?section=problems&id=101 å°ãé ã使ã£ãã ãã ã®éå·®æ°åã¯1次ã®å¤é å¼ ï¼éã®éå·®æ°åã¯ï¼æ¬¡ã®å¤é å¼ ï¼éã®éå·®æ°åã¯ï¼æ¬¡ã®å¤é å¼ néã®éå·®æ°åã¯n次ã®å¤é å¼ ãªã®ã§ éå·®ã®å±±ãä½ã£ã¦ åé«ãã®å³ç«¯ã®æ°åãå ¨é¨è¶³â¦
http://projecteuler.net/index.php?section=problems&id=218 ã¤ãã«100åã ã«å¯¾ã㦠ã¨ãã㨠ã®pell equationã«ã ã¨ããã§ãpell equationã®è§£ã¯æå°ã®è§£ããé ã«çæã§ããã¿ããã ãã© ãªãã§ï¼ã¯ããã®è§£ãnä¹ãã¦ã解ãªã®ã¯ããããã© éã«è§£ããªãâ¦
http://projecteuler.net/index.php?section=problems&id=99 ãã®ã¾ã¾ãlog使ã£ã¦æ¯è¼ã import Data.List import Data.Ord logPow x y = y*(log $ x) main = do f<-readFile "base_exp.txt" let xs = map (read.g) . lines $ f ::[[Double]] ans = maximumBâ¦
http://projecteuler.net/index.php?section=problems&id=103è¯ãåãããªããããã¨ããããå ¥åãã¦ã¿ãããã£ã¦ããã å¾ã§ã³ã¼ããããã[追è¨] Problem 105ãå©ç¨ import Data.List import Data.Ord monotone xs = all (f.sort$xs) [1..length xs `div`â¦
http://projecteuler.net/index.php?section=problems&id=98 ã¢ãã°ã©ã ãã¤å¹³æ¹æ°ã«ãªãæåã®çµã®ãã¡ãæ大ã®å¹³æ¹æ°ãæ±ããã å é ï¼ã ããå¿ãã¦ããã import Data.List import Data.Function import qualified Data.Map as Map findAnagrams xs = mapâ¦
http://projecteuler.net/index.php?section=problems&id=96æ°ç¬ã解ãåé¡ããã£ã¨éãåãããã«ãªã£ãã ã¾ã£ããããã°ã大å¤ã ã£ãã import Data.List import Data.Char import Data.Ord import Data.Array.IArray import Control.Monad type Sudoku =â¦
è³æä½ããçµãããªã件ã«ã¤ãã¦
powMod a n m | n < 3 = a^n `mod` m | otherwise = let (q,r) = divMod n 2 aq = powMod a q m in aq*aq*a^r `mod` m main = print $ (powMod 2 7830457 (10^10) * 28433 + 1) `mod` (10^10)
http://projecteuler.net/index.php?section=problems&id=94 ã¾ããpell equation. next (x,y) = (2*x+3*y,2*y+x) tolength x | (x+2) `mod` 3 == 0 = let a = (x+2) `div` 3 in 6*a-2 | (x-2) `mod` 3 == 0 = let a = (x-2) `div` 3 in 6*a+2 p094 = takeWhâ¦
http://projecteuler.net/index.php?section=problems&id=93 ã¨ããããç´ ç´ã«å ¨çæãã¦ãæ¢ç´¢ã import Data.List import Data.Ratio perm [] = [[]] perm xs@(_:_) =concat[map (h:)$perm(delete h xs)|h<-xs] calc fs xs = concatMap (calc' fs) . perm â¦