This file contains 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
/*- | |
* usage | |
* try { | |
* ... | |
* } | |
* catch ( Exception ex ) { | |
* showException( null, true, ex ); | |
* } | |
*/ |
This file contains 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
sum([x for x in range(1,1000) if x % 3 == 0 or x % 5 == 0]) |
This file contains 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
(define fib | |
(lambda (limit) | |
(letrec ((loop (lambda (a b lst) | |
(let ((s (+ a b))) | |
(if (<= limit s) | |
lst | |
(loop b s (append lst (list s)))))))) | |
(loop 1 2 (list 1 2))))) | |
(fib 4000000) |
This file contains 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
factor :: Integer -> [Integer] | |
factor n = factor_iter n 2 [] | |
factor_iter :: Integer -> Integer -> [Integer] -> [Integer] | |
factor_iter n x xs | n < x = reverse xs | |
| n `mod` x == 0 = factor_iter (n `div` x) x (x:xs) | |
| otherwise = factor_iter n (x + 1) xs | |
main = print (maximum((factor 600851475143))) |
This file contains 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
-- Haskell練習 | |
-- 五目並べ | |
-- 石の定義。 | |
data Ishi = Blank | |
| Black | |
| White | |
deriving (Eq) |
This file contains 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
import Data.List | |
-- 牌の定義 | |
data HaiData = Manzu Int | |
| Pinzu Int | |
| Souzu Int | |
| Ton | |
| Nan | |
| Sha | |
| Pei |
This file contains 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
-- | |
-- 3桁x3桁で6桁の回文積をつくる | |
-- | |
-- 3桁x3桁の集合 | |
[ x*y | x <- [100..999], y <- [100..999] ] | |
-- XxYとYxXは同じなので、片方だけにする | |
[ x*y | x <- [100..999], y <- [100..999], x <= y ] |
This file contains 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
{- | |
1~20で割りきれる最小の数 = 最小公倍数 | |
-> 1と2の最小公倍数、その数と3の最小公倍数、その数と4の最小公倍数、... | |
-> reduceを使う。haskellだとfoldlとか。 | |
-} | |
foldl lcm 1 [2..20] |
This file contains 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
{- | |
1~100までの二乗の和と、1~100までの和の二乗との差分を求める。 | |
1~100までの二乗の和 | |
foldl (+) 0 $ map (^ 2) [1..100] | |
1~100までの和の二乗 | |
(^ 2) $ foldl (+) 0 [1..100] | |
-} |
This file contains 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
(defun generate-numseq (size) | |
"指定したサイズの数列を作る" | |
(let ((gen-list '())) | |
(labels ((gen (current num-list) | |
(if (< current size) | |
(loop for x from 1 to size | |
if (not (member x num-list)) | |
do (gen (1+ current) (cons x num-list))) | |
(push num-list gen-list)))) | |
(loop for x from 1 to size |
OlderNewer