Skip to content

Instantly share code, notes, and snippets.

View tnoda's full-sized avatar

Takahiro Noda tnoda

View GitHub Profile
@tnoda
tnoda / admiral.clj
Last active December 27, 2015 20:29
Translating the `break` statement into Clojure.
(let [m (BattleMap. "Ironbottom Sound")
f (Fleet. "Center Fleet")]
(loop []
(doto f .repair .supply)
(when (and (.isFullyRepaired f)
(.isFullySupplied f)
(>= (.morale f) 40))
(.attack f m)
(if (-> m .gauges pos?)
(recur))))
@tnoda
tnoda / PrimeNumber.scala
Last active August 29, 2015 14:00
Sieve of Eratosthenes in Scala
import scala.annotation._
import scala.collection.mutable.ArrayBuffer
object PrimeNumber {
def apply(n: Int = 1000000): Array[Int] = sieve(n)
def sieve(n: Int): Array[Int] = {
val primes = new ArrayBuffer[Int]
val isPrime = Array.fill(n + 1)(true)
@tnoda
tnoda / BinarySearch.scala
Last active August 29, 2015 14:01
An unoptimized Scala equivalent of C++'s std::lower_bound and std::upper_bound
import scala.annotation.tailrec
object BinarySearch {
def lowerBound(xs: Array[Int], x: Int): Int = {
@tailrec
def loop(first: Int, count: Int): Int =
if (count == 0) first
else {
val step = count / 2
if (xs(first + step) < x) loop(first + step + 1, count - step - 1)
@tnoda
tnoda / union_find.py
Created June 24, 2014 08:34
Union-Find in Python
class UnionFind:
"""Weighted quick-union with path compression.
The original Java implementation is introduced at
https://www.cs.princeton.edu/~rs/AlgsDS07/01UnionFind.pdf
>>> uf = UnionFind(10)
>>> for (p, q) in [(3, 4), (4, 9), (8, 0), (2, 3), (5, 6), (5, 9),
... (7, 3), (4, 8), (6, 1)]:
... uf.union(p, q)
@tnoda
tnoda / pe10.clj
Last active August 29, 2015 14:03
Project Euler Problem 10 は Clojure でやっても 100ms 未満で計算できるはず。
(ns tnoda.pe10)
(defn- sieve
"Returns an array of primes below len. Retrieved from
https://github.com/tnoda/tnoda.math.prime."
[^long len]
(let [n len
not-prime (doto (boolean-array n)
(aset 0 true)
(aset 1 true))
@tnoda
tnoda / mell.el
Last active October 26, 2015 17:34
Mirror of some taiyaki.org elisp files
;;; mell.el --- MELL Emacs Lisp Library
;;
;; AUTHOR: Hiroyuki Komatsu <komatsu@taiyaki.org>
;; LICENCE: GPL2
;; $Id: mell.el,v 1.4 2003/03/18 03:34:45 komatsu Exp $
;; Version: 1.4.0
;;
;; ------------------------------------------------------------
;; XEmacs と FSF Emacs の差異を吸収
@tnoda
tnoda / cf.go
Last active August 29, 2015 14:04
cf.go
package main
import (
"bufio"
"errors"
"fmt"
"io"
"os"
"strconv"
)
@tnoda
tnoda / mon-css-color.el
Created July 28, 2014 06:09
Mirror mon-css-color.el
;;; mon-css-color.el --- Highlight and edit CSS colors
;; -*- mode: EMACS-LISP; -*-
;;; ================================================================
;; Copyright © 2009, 2010 MON KEY. All rights reserved.
;; Copyright © 2008, 2009 Lennart Borgman
;; Copyright © 2008 Niels Giesen
;;; ================================================================
;; AUTHOR: Niels Giesen
$ make recipes/helm-ad
• Building recipe helm-ad ...
emacs --no-site-file --batch -l package-build.el --eval "(let ((package-build-stable nil) (package-build-archive-dir (expand-file-name \"./packages\" pb/this-dir))) (package-build-archive 'helm-ad))"
Error reading recipe /Users/tnoda/work/melpa/recipes/helm-ad~: Recipe 'helm-ad~' contains mismatched package name 'helm-robe'
;;; helm-ad
Fetcher: github
Source: tnoda/helm-ad

ぼっち.scala --- 「ぼっち」でも始められる Scala

第4回 Scala 関西ビギナーズ (session|LT) の提案.

概要

Scala はその人気の高まりとともに世界的には普及期に入りつつある. 日本においても,東京都心の D 社や D 社などを中心に Scala プログラマーが増えつつある. しかし,関西を含むほとんどの地域では Scala プログラマーお人口密度が低く,