Skip to content

Instantly share code, notes, and snippets.

View tnoda's full-sized avatar

Takahiro Noda tnoda

View GitHub Profile
@tnoda
tnoda / heap.clj
Created July 11, 2012 03:02
Priority Queue in Clojure
(use 'clojure.test)
(set! *unchecked-math* true)
(defprotocol Heap
"Protocol for heap."
(push! [this x])
(pop! [this]))
(defrecord LongHeap [^longs heap, size]
@tnoda
tnoda / hoge.clj
Created July 14, 2012 16:07 — forked from ponkore/hoge.clj
RubyにおけるシーケンスはObject#repeatに任せなさい!を Clojure でやってみた
;;; http://melborne.github.com/2012/07/12/object-repeat-take-care-of-sequence/
;;; を Clojure でやってみた。
;;; 9.、10. は挫折www
;;; 1. 初項1、公差2の等差数列の最初の20項を求めなさい。
(take 20 (iterate #(+ % 2) 1))
;;; => (1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39)
;;; 2. 初項3、公比2の等比数列の最初の20項を求めなさい。
(take 20 (iterate #(* % 2) 3))
@tnoda
tnoda / eight-puzzle.clj
Created July 24, 2012 05:53
Eight Puzzle in Clojure
(ns tnoda.bfs.eight-puzzle
(:import clojure.lang.PersistentQueue)
(:use clojure.test))
(defn- board->state
[board]
{:board board
:zero (first (for [i (range 3)
j (range 3)
:when (= 0 (get-in board [i j]))]
@tnoda
tnoda / topological_sort.clj
Created August 8, 2012 14:25
Topological Sort in Clojure
(ns tnoda.algorithm.topological-sort
(:import (java.util LinkedList BitSet Stack))
(:use clojure.test))
(defn- dfs-forest!
[g ^LinkedList order ^BitSet discovered ^Stack stack ^BitSet on-stack]
(letfn [(discover
[u]
(let [adjacencies (g u)]
(when (not-any? #(.get on-stack %) adjacencies)
@tnoda
tnoda / big.clj
Created September 5, 2012 05:53 — forked from halcat0x15a/big.clj
user> (bench insert-vector [] 1000)
"Elapsed time: 117.616 msecs"
[835 483 229 138 454 643 450 636 792 357 35 455 986 249 181 25 966 519 590 71 ...]
user> (bench insert-vector' [] 1000)
"Elapsed time: 61.382 msecs"
[545 468 921 491 728 783 577 15 620 231 787 537 8 435 730 842 334 55 527 534 ...]
@tnoda
tnoda / cmigemo.rb
Created October 28, 2012 06:35
A private cmigemo formula.
require 'formula'
class Cmigemo < Formula
homepage 'http://www.kaoriya.net/software/cmigemo'
url 'http://cmigemo.googlecode.com/files/cmigemo-default-src-20110227.zip'
md5 '6e9b6f6ec96d4eb8bdd18e52b91e1b85'
depends_on 'nkf'
def patches
@tnoda
tnoda / problem.md
Created November 14, 2012 12:25 — forked from Kuchitama/Probrem1.clj
Nine solutions to Problem 1 of Project Euler in Clojure

Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.


Retrieved from http://projecteuler.net/problem=1, on Nov 14 2012.

@tnoda
tnoda / ja.org
Created November 16, 2012 11:50
A small rant about ClojureScript

みじかい ClojureScript のはなし

@tnoda
tnoda / problem_2.clj
Created December 7, 2012 13:58
Project Euler Problem 2 #mitori_clj
(defn fib
"Returns the nth Fibonacci number."
^long
[n]
(-> (* 0.5 (inc (Math/sqrt 5))) ; golden ratio
(Math/pow n)
(/ (Math/sqrt 5))
(+ 0.5)
Math/floor
long))
@tnoda
tnoda / problem_5.clj
Created December 11, 2012 14:50
Project Euler Problem 5 #mitori_clj
(ns tnoda.projecteuler.problem-5
(:import org.apache.commons.math.util.MathUtils) ; [org.apache.commons/commons-math "2.2"]
(:use clojure.test))
(defn- solver*
[n]
(reduce (fn [^long x ^long y] (MathUtils/lcm x y)) (range 1 (inc n))))
(def solver (partial solver* 20))