Skip to content

Instantly share code, notes, and snippets.

View Koitaro's full-sized avatar

Yasusi Koibuti Koitaro

View GitHub Profile
@Koitaro
Koitaro / Pythagoreans.dcl
Created July 27, 2010 15:21
Pythagoreans
definition module Pythagoreans
:: ListTree a = Node a [ListTree a]
primitivePythagoreanTree :: ListTree [Int]
pythagoreans :: ([Int] -> Bool) -> [[Int]]
definition module BinaryTree
:: BinaryTree a = Node a (BinaryTree a) (BinaryTree a) | Leaf
(!!!) infixl 9 :: (BinaryTree a) Int -> a
definition module PascalsTriangle
pascalsTriangle :: [[BigInt]]
C :: Int Int -> BigInt
@Koitaro
Koitaro / IntegerPartitions.dcl
Created August 20, 2010 23:21
IntegerPartitions
definition module IntegerPartitions
integerPartitions :: Int Int -> [[Int]]
definition module AltEnv
($) infixr 1 :: (a -> b) a -> b
S :: (a b -> c) (a -> b) a -> c
Y :: (a -> a) -> a
@Koitaro
Koitaro / gist:653536
Created October 29, 2010 13:17
xml.tcl
package require Itcl; namespace import ::itcl::*
proc quote arg { string map {& &amp; \" &quot; ' &apos; < &lt; > &gt;} $arg }
class XmlAttributes {
variable Attributes {}
constructor arg {
dict for {k v} $arg {dict set Attributes $k $v}
}
method configure arg {
@Koitaro
Koitaro / 0001.hs
Created February 4, 2011 03:51
Haskell : Project Euler 1-9
module Main where
import Data.List.Ordered (union)
main :: IO ()
main = print . sum . takeWhile (1000 >) $ union [3,6..] [5,10..]
@Koitaro
Koitaro / 127
Created February 7, 2011 06:47
Clean : Project Euler 120 - 129
module main
import StdEnv, StdLib, BigInt
fact :: (Int -> [Int])
fact = f [2:[3,5..]] where
f [x:xs] n
| n == 1 = []
| x*x > n = [n]
| n rem x == 0 = [x:f [x:xs] (n/x)]
| otherwise = f xs n
@Koitaro
Koitaro / 1.swi
Last active January 6, 2017 12:12
Prolog : Project Euler 1-9
problem1(Answer) :- aggregate(sum(N),num(N),Answer).
num(N) :- between(1,999,N), answer(N).
answer(N) :- N rem 3 =:= 0, !.
answer(N) :- N rem 5 =:= 0.
@Koitaro
Koitaro / 10.swi
Created February 12, 2011 23:59
Prolog : Project Euler 10-19
:- use_module(library(primes),[set_primes/1,prime/1,erase_primes/0]).
problem10(Answer) :-
set_primes(2000000),
aggregate(sum(N),prime(N),Answer),
erase_primes.