This file contains hidden or 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
(use 'clojure.walk) | |
(defn all-add [seq] | |
(prewalk #(if (not (coll? %)) (+ % 1) %) | |
seq)) | |
(all-add [1]) | |
(all-add [1 2]) | |
(all-add [1 [2]]) | |
(all-add [[1][2]]) |
This file contains hidden or 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
-- http://ideone.com/WeepT | |
solve = max' . map sum $ seq | |
where | |
tri = [2,3,4,5,10] | |
seq =[ [x,y,z] | x <- tri, y <- tri , z <- tri | |
, x/=y,y=z,x/=z,x<(y+z) | |
] | |
max' = foldr1 max | |
main = print $ solve |
This file contains hidden or 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
euler9 = [ (a*b*z)|m<-[1..1000],n<-[1..1000],m>n,let z = m*m+n*n | |
, let a = m*m-n*n | |
, let b = 2*m*n | |
, (a+b+z)==1000 | |
] |
This file contains hidden or 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
{-- | |
素数の求めかたはこちらを参考にしました | |
http://haskell.g.hatena.ne.jp/nobsun/20060617/p1 | |
--} | |
primes = 2:filter prime [3..] | |
prime n = all ((0/=) . mod n) $ takeWhile ((n>=) . s (*) id) primes | |
s f g x = f x (g x) | |
euler10 = sum . takeWhile (<=2000000) $ primes |
This file contains hidden or 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
open F, "./euler11.txt" or die "dead\n"; | |
print "["; | |
foreach $v (<F>) | |
{ | |
@arr = split(/\s/,$v); | |
print join(',',@arr), "\n"; | |
} | |
print "]\n"; |
This file contains hidden or 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
{-# LANGUAGE NoMonomorphismRestriction #-} | |
module Main where | |
import Data.Array | |
lst = | |
[08,02,22,97,38,15,00,40,00,75,04,05,07,78,52,12,50,77,91,08 | |
,49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,04,56,62,00 | |
,81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,03,49,13,36,65 | |
,52,70,95,23,04,60,11,42,69,24,68,56,01,32,56,71,37,02,36,91 | |
,22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80 |
This file contains hidden or 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
{-# LANGUAGE NoMonomorphismRestriction #-} | |
module Main where | |
import Data.List (group,find) | |
import Data.Maybe (fromJust) | |
primes = 2:filter prime [3..] | |
prime n = all ((0/=) . mod n) $ takeWhile ((n>=) . s (*) id) primes | |
s f g x = f x (g x) | |
This file contains hidden or 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
module Main where | |
euler14 = max' [(length xs, n) | n<-[1..1000000], let xs = (collatz n)] | |
where | |
comp x y = if (fst x) > (fst y) then x else y | |
max' = (foldr comp (0,0)) | |
This file contains hidden or 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
-- http://www.itmedia.co.jp/enterprise/articles/1003/06/news002.html | |
-- http://haskell.g.hatena.ne.jp/hyuki/20060612/combination | |
module Euler15 where | |
euler15 = c 40 20 | |
c n k = n^>k `div` k^>k | |
where | |
n^>k = foldr (*) 1 [n-k+1..n] |
This file contains hidden or 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
module Euler16 where | |
import Data.Maybe (fromMaybe) | |
euler16 = sum . strToInt $ text | |
where | |
num = 2 ^ 1000 | |
text = show num | |
charToInteger = flip lookup (zip ['0'..'9'] [0..9]) | |
strToInt = map (fromMaybe 0 . charToInteger) |
OlderNewer