Skip to content

Instantly share code, notes, and snippets.

@takuma7
takuma7 / gist:641678
Created October 23, 2010 02:08
Project Euler - Problem 4
import System.IO
main = do
putStrLn $ biggest "0" [ show (a*b) | a <- [100..999], b <- [100..999], isPalindromicNum (show (a*b))]
isPalindromicNum [] = True
isPalindromicNum (_:[]) = True
isPalindromicNum (x:xs) | x == last xs = isPalindromicNum (init xs)
| otherwise = False
@takuma7
takuma7 / gist:641677
Created October 23, 2010 02:07
Project Euler - Problem 3
import System.IO
main = do
putStrLn $ show $ last $ filter ((== 0) . (mod 600851475143)) (takeWhile (< (truncate (sqrt 600851475143))) prime)
prime = 2:f [3] [3,5..]
where f (x:xs) ys = let (ps, qs) = span (< x^2) ys
in ps ++ f (xs ++ ps) [z | z <- qs, z `mod` x /= 0]
@takuma7
takuma7 / gist:640522
Created October 22, 2010 13:24
Project Euler - Problem 2
import System.IO
main = do
putStrLn $ show $ sum $ filter even $ takeWhile ((>) 4000000) fib
fib = 1:2:[ a+b | (a,b) <- zip fib (tail fib)]
@takuma7
takuma7 / gist:640516
Created October 22, 2010 13:18
Project Euler - Problem 1
import System.IO
main = do
putStrLn $ show $ sum $ filter judge [1..999]
judge a | a `mod` 3 == 0 || a `mod` 5 == 0 = True
| otherwise = False
#include <stdio.h>
int main(void){
printf("Hello World!\n"); //this is a test
}