2010-02-01ãã1ã¶æéã®è¨äºä¸è¦§
Problem 67 http://projecteuler.net/index.php?section=problems&id=67 ä¸ããé ã«è¨ç®ãã¦ãããä¸ã«åã¨å¾ãã©ã¡ããã«0ãä»å ãã¦å ç®ããã 3 3 0 0 3 7 4 7 4 7 4 -> 11 4 7 7 11 7 add a b = [ m + n | (m, n) <- zip a b ] next a b = [ max m n | (â¦
Problem 65 http://projecteuler.net/index.php?section=problems&id=65 é£åæ°ã®è¨ç®æ³ãé©ç¨ãããæåã«1ãä»å ããã¨è¨ç®ããããã digits 0 = [] digits n = (mod n 10):(digits (div n 10)) a = 2:1:2:1:[ if n == 1 then 1 else n + 2 | n <- tail aâ¦
ããã¸ã§ã¯ããªã¤ã©ã¼ http://projecteuler.net/index.php?section=problems&id=280 åé¡ã®æå³ãç解ããã®ã«5åãæ£ããç解ããã®ãã¯ä¸æã the lower row, the upper rowã®è§£éã«èªä¿¡ããªãã 2Ã2ãã¹ã®å ´åã¯ã§ããã¨æããã ãã©ããã以ä¸ã¯ã©ããã¦â¦
Problem 63 http://projecteuler.net/index.php?section=problems&id=63 9ã¾ã§ã§èããã°ããã num_digits n = length (takeWhile (>0) a) where a = n:[ div n 10 | n <- a ] count d = length (takeWhile (\(e,n) -> n == e) [ (e, num_digits (d^e)) | e â¦
Problem 97 æåã«ç¥ããã100ä¸æ¡ãè¶ ããç´ æ°ã¯1999å¹´ã«çºè¦ããããããã¦ããã¯26972593-1ã¨ããã¡ã«ã»ã³ãç´ æ°ã§ããã2098960æ¡ã§ããããã®å¾ãããã«å¤ãã®æ¡æ°ã®2p-1ã¨ããå½¢ã®ã¡ã«ã»ã³ãç´ æ°ãè¦ã¤ãã£ãã ããããªããã2004å¹´ã«2357207æ¡ã®å·¨å¤§â¦
http://projecteuler.net/index.php?section=problems&id=62 Haskellã§è¾æ¸ã¯æ¬¡ã®ããã«ä½¿ãã import qualified Data.Map as M m = M.insert 1 2 M.empty n = m M.! 1 -- 2 b = M.member 1 m -- True 3ä¹ãã¦åæ¡ã®æ°åãéé ã«ä¸¦ã¹ã¦æ°ã«ãããåãæ°ã«ãªâ¦
Problem 95 çç´æ°ã¯ãã®æ°èªä¿¡ãé¤ããç´æ°å ¨ã¦ã§ãããä¾ãã°ã28ã®çç´æ°ã¯1,2,4,7,14ã¨ãªãããã®åã¯28ã¨ãªãã®ã§ããããå®å ¨æ°ã¨å¼ã¶ã é¢ç½ããã¨ã«220ã®çç´æ°ã®åã¯284ã§284ã®çåæ°ã®åã¯220ã§ãããããã¯2ã¤ã®æ°ããæããã§ã¼ã³ãæãããããâ¦
http://projecteuler.net/index.php?section=problems&id=61 Arrayã§æåã°ã©ããä½ãã
Problem 94 辺ã®é·ããæ´æ°ã§é¢ç©ãæ´æ°ã®æ£ä¸è§å½¢ãåå¨ããªããã¨ã¯ç°¡åã«ç¤ºãããããããããã»ã¼æ£ä¸è§å½¢ãã®5-5-6ã¨ããä¸è§å½¢ã¯12å¹³æ¹åä½ã®é¢ç©ãæã¤ã ãã»ã¼æ£ä¸è§å½¢ãã2ã¤ã®è¾ºã®é·ããçãã第ä¸ã®è¾ºã¯ããã¨1åä½ããéããªãä¸è§å½¢ã¨å®ç¾©ããâ¦
http://projecteuler.net/index.php?section=problems&id=59 3åå²ãã¦ãããããæé »ã®æ°ãé¸ãã§ãããã¯ã¹ãã¼ã¹ã ã¨ã¿ã¦ããã¼ãä½ãã
Problem 93 éå{1, 2, 3, 4}ããä¸åº¦ãã¤æ°åã使ã£ã¦4ã¤ã®æ¼ç®åï¼+, -, *, /ï¼ã¨ã«ãã³ã使ã£ã¦ãéãæ£ã®æ´æ°ãæããã¨ãã§ããã ä¾ãã°ã 8 = (4 * (1 + 3)) / 2 14 = 4 * (3 + 1 / 2) 19 = 4 * (2 + 3) - 1 36 = 3 * 4 * (2 + 1) 12 + 34ã®ãããªæ°â¦
Problem 57 http://projecteuler.net/index.php?section=problems&id=57 æéããããã®ã¯æ¡æ°ã®ã«ã¦ã³ãã num_digits 0 = 0 num_digits n = 1 + (num_digits (div n 10)) a = take 1000 ((1,1):[ (p + q * 2, p + q) | (p, q) <- a ]) main = print (lengtâ¦
Problem 92 åã«åºã¦ããæ°ã«ãªãã¾ã§æ°ããæ°ãä½ãããæ°ã®ãã§ã¼ã³ãæ°ã®åæ¡ã®å¹³æ¹åãé£ç¶çã«å ãããã¨ã«ããä½ãããã ä¾ãã°ã 44 â 32 â 13 â 10 â 1 â 1 85 â 89 â 145 â 42 â 20 â 4 â 16 â 37 â 58 â 89 ããã«1ã89ã«å°éããã©ã®ãã§ã¼ã³ãâ¦
Problem 55 http://projecteuler.net/index.php?section=problems&id=55 ç¹ã«ãªã«ããªãã digits 0 = [] digits n = (digits (div n 10)) ++ [mod n 10] numerize a = foldl1 (\x y -> x * 10 + y) a rev = numerize . reverse . digits is_palindromic n =â¦
Problem 91 ç¹P(x1, y1)ã¨Q(x1, y2)ãæ ¼åç¹ä¸ã«ããããããã«åç¹O(0, 0)ãå ãã¦â³OPQãå½¢æããã ã©ã®åº§æ¨ã0ã¨2ã®éã«ããå ´åã14åã®ç´è§ä¸è§å½¢ãããï¼ä¸ç¥ï¼ã 0 ⤠x_1, y_1, x_2, y_2 ⤠50ã®ã¨ããç´è§ä¸è§å½¢ã¯ããã¤ãããã http://projecteulerâ¦
http://projecteuler.net/index.php?section=problems&id=54 ã«ã¹ã¿ã ã®ã½ã¼ãã¯sortByã使ãã import Data.List a = [ 3, 1, 4, 1, 5 ] b = sort a -- [1,1,3,4,5] c = zip [1..] a d = sortBy cmp c -- [(2,1),(4,1),(1,3),(3,4),(5,5)] cmp (n1,m1) (n2,â¦
ããã¸ã§ã¯ããªã¤ã©ã¼ http://projecteuler.net/index.php?section=problems&id=279 ããããåé¡æãçããã®ã¯é£ããã«ã¡ãããªããæéããã¾ããªãããã£ãããããã ããã«ãã¤ãã®ãã¿ã¼ã³ã§ãããã¨ãããã£ãããããããªããªããã¾ããããªããçµâ¦
Problem 52 http://projecteuler.net/index.php?section=problems&id=52 6åãã¦ãæ¡ãä¸ãããªããã¨ãå©ç¨ããã import Data.List digits 0 = [] digits n = (digits (div n 10)) ++ [mod n 10] normalize = sort . digits is_valid n = f n 2 where m = â¦
Problem 88 èªç¶æ°Nãå°ãªãã¨ã2ã¤ã®èªç¶æ°ã®éå{a1, a2, ... , ak}ã®åã¨ç©ã§æ¸ããã¨ãããããç©åæ°ã¨å¼ã¶ï¼N = a1 + a2 + ... + ak = a1 à a2 à ... à akã ä¾ãã°ã6 = 1 + 2 + 3 = 1 à 2 à 3ã ä¸ãããã大ããkã¨ã®éåã«å¯¾ãã¦ããã®æ§è³ªãæã¤â¦
Problem 50 http://projecteuler.net/index.php?section=problems&id=50 2ããå§ã¾ãç³»åã3ããå§ã¾ãç³»åãããªã¹ãã«ãã¦ãé·ããã®ãã調ã¹ã¦ãããé ãã import Data.Array sieve a p | a!p == True = sieve (a // [ (m, False) | m <- b, a!m ]) (p +â¦
Problem 86 èèSãç´æ¹ä½ã§å¤§ããã6Ã5Ã3ã®é¨å±ã®ä¸ã¤ã®è§ã«åº§ã£ã¦ãããè¿Fãå対å´ã®è§ã«åº§ã£ã¦ãããé¨å±ã®è¡¨é¢ãé²ãã§SããFã®æçã®ãç´ç·ãè·é¢ã¯10ï¼ä¸ç¥ï¼ã ã©ã®ä¸ããããç´æ¹ä½ã«ããæçãçµè·¯åè£ã3ã¤ã¾ã§ããããã®æçã«ã¼ãã¯ãã¤ãæ´æ°â¦
Problem 48 http://projecteuler.net/index.php?section=problems&id=48 å°ä½ãåããªãã¦ãç¬æã«çããåºãã n = 1000 s = show (sum [ k^k | k main = print(reverse (take 10 (reverse s))) Problem 49 http://projecteuler.net/index.php?section=probâ¦
Problem 82 ä¸ã®5Ã5ã®è¡åã®å·¦ã®åã®è¦ç´ ã®ã©ããããåºçºãã¦å³ã®åã®ãã¹ã®ã©ããã«å°çãã¦ãé²ãæ¹åã¯ä¸ä¸å³ã®çµè·¯ã§åãæå°ã®ãã®ã¯ãä¸ã«èµ¤ã¨å¤ªåã§ç¤ºãããããã®åã¯994ã§ããã .path { font-weight:bold; color:red } 131 673 234 103 18 201 96â¦
http://projecteuler.net/index.php?section=problems&id=47 é ã«ç´ å æ°å解ããã°çãã¯åºãã is_prime n = all (\p -> mod n p /= 0) (takeWhile (\p -> p * p <= n) primes) primes = 2:(filter is_prime [3,5..]) div_pow n p | mod n p /= 0 = (n, 0) â¦
Problem 80 èªç¶æ°ã®å¹³æ¹æ ¹ãæ´æ°ã§ãªããã°ãç¡çæ°ã§ãããã¨ãç¥ããã¦ããããã®ãããªå¹³æ¹æ ¹ã®å°æ°ã®å±éã¯ç¡éã§ç¹°ãè¿ãã¯ãªãã 2ã®å¹³æ¹æ ¹ã¯1.41421356237309504880...ã§ãæåã®100æ¡ã®åæ¡ã®åã¯475ã§ããã æåã®100åã®èªç¶æ°ã«å¯¾ãã¦ãç¡çæ°â¦
Problem 45 http://projecteuler.net/index.php?section=problems&id=45 å è§æ°ã¯ä¸è§æ°ãªã®ã§ãä¸è§æ°ã¯ç¡è¦ã§ãããäºè§æ°ã¨å è§æ°ã並ã¹ã¦æ¯è¼ãã¦ããã ãã polygonal p = [ div (n * ((p - 2) * n - (p - 4))) 2 | n equal (p:ps) (h:hs) | p == h = [â¦
Problem 77 10ã¯ç´ æ°ã®åã«5ã¤ã®æ¹æ³ã§æ¸ããã 7 + 3 5 + 5 5 + 3 + 2 3 + 3 + 2 + 2 2 + 2 + 2 + 2 + 2 ç´ æ°ã®åã§æ¸ãæ¹æ³ã5000ãè¶ ããæåã®å¤ã¯ããã¤ãã http://projecteuler.net/index.php?section=problems&id=77 åå²æ°ã®ç´ æ°çã¨ãè¨ãã¹ããã®â¦
http://projecteuler.net/index.php?section=problems&id=44 ã¾ããã§ããã ãæ°å¦ã使ããªãæ¹æ³ã§æ¸ãããPlãlãå°ããã»ããã調ã¹ãPkã¨ã®åãäºè§æ°ã§ãããã®ãæ¢ãããã ããkã¯Pk+1-Pk ⤠Plãæºããéãããã®ä¸ã§Pl + 2Pkãäºè§æ°ã§ãããã®ãæ¢ãâ¦
Problem 76 5ã¯6ã¤ã®éãæ¹æ³ã§åã«æ¸ããã 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 2 + 1 + 1 + 1 1 + 1 + 1 + 1 + 1 100ãå°ãªãã¨ã2ã¤ã®åã«æ¸ãæ¹æ³ã¯ä½éããããã http://projecteuler.net/index.php?section=problems&id=76 ããã¯åå²æ°ã¨è¨ããããã®â¦
http://projecteuler.net/index.php?section=problems&id=43 ã©ã¤ãã©ãªã§é åãåºãã¦å¤å®ããã¨é常ã«é ãã import Data.List primes = [2,3,5,7,11,13,17] numerize a = foldl (\x y -> x * 10 + y) 0 a is_valid a [] = True is_valid a (p:ps) = if moâ¦