Skip to content

Instantly share code, notes, and snippets.

View tnoda's full-sized avatar

Takahiro Noda tnoda

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / naive-primes.clj
Created July 1, 2012 14:51
Sieve of Eratosthenes in Clojure
(defn prime? [n]
(every? #(pos? (rem n %)) (range 2 (Math/sqrt (inc n)))))
(defn naive-primes [n]
(filter prime? (range 2 (inc n))))
@tnoda
tnoda / core.clj
Created June 9, 2012 08:05
learn-you-a-haskell.geometry
(ns learn-you-a-haskell.geometry.core
(:require (learn-you-a-haskell.geometry [sphere :as sphere]
[cuboid :as cuboid]
[cube :as cube])))
(defn -main
"I don't do a whole lot."
[& args]
(print (sphere/volume 10)))
@tnoda
tnoda / core.clj
Created May 17, 2012 08:15
Inverse Fizzbuzz solver in Clojure
;; Question: Inverse FizzBuzz (Clojure version) - Given a collection
;; whose elements are one of :fizz, :buzz, and :fizzbuzz, what's the
;; shortest contiguous sequence of numbers that produces that list when
;; you run fizzbuzz ?
;;
;; Originally introduced at:
;; http://www.jasq.org/2/post/2012/05/inverse-fizzbuzz.html
(ns tnoda.inverse-fizzbuzz.core
(:use [clojure.test :only [deftest are]]))
@tnoda
tnoda / cljdoc.el
Created April 9, 2012 01:57
cljdoc.el --- eldoc mode for clojure
;;; cljdoc.el --- eldoc mode for clojure
;; Copyright (C) 2011 tomykaira
;; Version 0.1.0
;; Keywords: eldoc clojure
;; Author: tomykaira <[email protected]>
;; URL: https://gist.github.com/1386472
;; This file is not part of GNU Emacs.