Skip to content

Instantly share code, notes, and snippets.

View tamurashingo's full-sized avatar
🆑
I'm writing CommonLisp

tamura shingo tamurashingo

🆑
I'm writing CommonLisp
  • Saitama, Japan
View GitHub Profile
@tamurashingo
tamurashingo / gist:3911386
Created October 18, 2012 12:05
show the stacktrace
/*-
* usage
* try {
* ...
* }
* catch ( Exception ex ) {
* showException( null, true, ex );
* }
*/
sum([x for x in range(1,1000) if x % 3 == 0 or x % 5 == 0])
(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)
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)))
-- Haskell練習
-- 五目並べ
-- 石の定義。
data Ishi = Blank
| Black
| White
deriving (Eq)
@tamurashingo
tamurashingo / gist:4597233
Last active December 11, 2015 11:58
麻雀つくり中。。。
import Data.List
-- 牌の定義
data HaiData = Manzu Int
| Pinzu Int
| Souzu Int
| Ton
| Nan
| Sha
| Pei
@tamurashingo
tamurashingo / gist:5004906
Created February 21, 2013 14:01
Project Euler 4
--
-- 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 ]
@tamurashingo
tamurashingo / gist:5018581
Created February 23, 2013 05:23
Project Euler 5
{-
1~20で割りきれる最小の数 = 最小公倍数
-> 1と2の最小公倍数、その数と3の最小公倍数、その数と4の最小公倍数、...
-> reduceを使う。haskellだとfoldlとか。
-}
foldl lcm 1 [2..20]
@tamurashingo
tamurashingo / gist:5018596
Created February 23, 2013 05:31
Project Euler 6
{-
1~100までの二乗の和と、1~100までの和の二乗との差分を求める。
1~100までの二乗の和
foldl (+) 0 $ map (^ 2) [1..100]
1~100までの和の二乗
(^ 2) $ foldl (+) 0 [1..100]
-}
@tamurashingo
tamurashingo / sudoku_gen.lisp
Last active January 2, 2016 07:49
数独の問題を生成したい
(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