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
(* This is coq *) | |
Print nat. | |
Inductive nat : Set := | |
| O : nat | |
| S : nat -> nat. | |
Fixpoint plus (m n : nat) {struct m} : nat := | |
match m with | |
| O => n | |
| S m' => S (plus m' 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 Euler13 where | |
lst = [ | |
3,7,1,0,7,2,8,7,5,3,3,9,0,2,1,0,2,7,9,8,7,9,7,9,9,8,2,2,0,8,3,7,5,9,0,2,4,6,5,1,0,1,3,5,7,4,0,2,5,0, | |
4,6,3,7,6,9,3,7,6,7,7,4,9,0,0,0,9,7,1,2,6,4,8,1,2,4,8,9,6,9,7,0,0,7,8,0,5,0,4,1,7,0,1,8,2,6,0,5,3,8, | |
7,4,3,2,4,9,8,6,1,9,9,5,2,4,7,4,1,0,5,9,4,7,4,2,3,3,3,0,9,5,1,3,0,5,8,1,2,3,7,2,6,6,1,7,3,0,9,6,2,9, | |
9,1,9,4,2,2,1,3,3,6,3,5,7,4,1,6,1,5,7,2,5,2,2,4,3,0,5,6,3,3,0,1,8,1,1,0,7,2,4,0,6,1,5,4,9,0,8,2,5,0, | |
2,3,0,6,7,5,8,8,2,0,7,5,3,9,3,4,6,1,7,1,1,7,1,9,8,0,3,1,0,4,2,1,0,4,7,5,1,3,7,7,8,0,6,3,2,4,6,6,7,6, | |
8,9,2,6,1,6,7,0,6,9,6,6,2,3,6,3,3,8,2,0,1,3,6,3,7,8,4,1,8,3,8,3,6,8,4,1,7,8,7,3,4,3,6,1,7,2,6,7,5,7, | |
2,8,1,1,2,8,7,9,8,1,2,8,4,9,9,7,9,4,0,8,0,6,5,4,8,1,9,3,1,5,9,2,6,2,1,6,9,1,2,7,5,8,8,9,8,3,2,7,3,8, |
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
pascal = [1]:[zipWith (+) (0:xs) (xs++[0])| xs <- pascal] |
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 Euler18 where | |
import Data.Map hiding (map) | |
import Data.List (scanr) | |
lst :: [[Integer]] | |
lst = [ | |
[75] | |
, [95,64] | |
, [17,47,82] | |
, [18,35,87,10] |
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 Euler19 where | |
import Control.Monad.List | |
euler19 = length [ (k,j,m,q) | | |
k <- [19 .. 20] | |
, j <- [0 .. 99] | |
, m <- [1 .. 12] | |
, q <- [1 .. 31] | |
, let n = (zeller k j m q) |
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 Euler20 where | |
import Data.Maybe (fromMaybe) | |
-- 文字(0-9)を数字に | |
charToInteger :: Char -> Maybe Integer | |
charToInteger = flip lookup (zip ['0'..'9'] [0..9]) | |
-- 文字列(0-9)*を数字に | |
strToInt :: String -> [Integer] | |
strToInt = map (fromMaybe 0 . charToInteger) |
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 Euler24 where | |
import Data.List (permutations, sort) | |
listToDigit xs = sum $ zipWith (*) (reverse xs) (iterate (*10) 1) | |
euler24 = listToDigit . f $ lst | |
where | |
f = (!!(1000000-1)) . sort . permutations | |
lst = [0..9] |
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 | |
{-- http://d.hatena.ne.jp/rst76/20090513/1242221572 --} | |
-- fib = 1:1:(zipWith (+) fib (tail fib)) | |
fib = fst . fib' | |
fib' 0 = (0,1) | |
fib' n | |
| even n = (f0, f1) | |
| otherwise = (f1, f2) |
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
#define size(array) (sizeof(array) / sizeof(array[0])) | |
void insertsort(int *a, int len) | |
{ | |
int j; | |
for (j=1; j<len; j++) { | |
int key = a[j]; | |
int i = j-1; | |
while (i>=0 && a[i]>key) { | |
a[i+1] = a[i]; |
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
function insertSort(a) | |
for j=1, table.maxn(a) do | |
key = a[j] | |
i = j-1 | |
while i>=1 and a[i]>key do | |
a[i+1] = a[i] | |
i = i-1 | |
end |