Skip to content

Instantly share code, notes, and snippets.

View tnoda's full-sized avatar

Takahiro Noda tnoda

View GitHub Profile
;; ess-R-object-popup.el
;;
;; I have defined a function, ess-R-object-popup, that when
;; invoked, will return a popup with some information about
;; the object at point. The information returned is
;; determined by which R function is called. This is controlled
;; by an alist, called ess-R-object-popup-alist. The default is
;; given below. The keys are the classes of R object that will
;; use the associated function. For example, when the function
;; is called while point is on a factor object, a table of that
@tnoda
tnoda / m-fib.clj
Last active December 11, 2015 01:19 — forked from plaster/memotest.clj
元は, @plaster による `memoize` を使ったメモ化再帰 (memotest.clj). オリジナルで atom を使っていたところを var に置きかえてみました (m-fib.clj).
(def ^:dynamic *m-fib*)
(defn fib
[n]
(let [fib* (memoize (fn
[x]
(if (< 1 x)
(+ (*m-fib* (dec x))
(*m-fib* (- x 2)))
1)))]
@tnoda
tnoda / problem_19.clj
Created January 5, 2013 04:50
#mitori_clj Project Euler Problem 19
(ns tnoda.projecteuler.problem-19
(:import (org.joda.time DateTime) ; [joda-time/joda-time "2.1"]
(org.joda.time.chrono GregorianChronology)))
(defn- a-month-later
[^DateTime dt]
(.plusMonths dt 1))
(defn- sunday?
[^DateTime dt]
@tnoda
tnoda / problem_11.clj
Created December 28, 2012 03:56
#mitori_clj Project Euler Problem 11
(ns tnoda.projecteuler.problem-11
[:require [clojure.string :as str]])
(def ^:private input "08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
@tnoda
tnoda / problem_12.clj
Created December 20, 2012 04:04
#mitori_clj Project Euler Problem 12
(ns tnoda.projecteuler.problem-12
(:use [org.clojars.tnoda.math.prime :only [sieve* prime-factors *prime-array*]]
clojure.test))
(defn- solver*
"Returns the value of the first triangle number to have over x divisors."
[x]
(binding [*prime-array* (sieve*)]
(let [triangle-numbers (reductions + (range))
nd (fn number-of-divisors
;;;A palindromic number reads the same both ways.
;;;The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
;;;Find the largest palindrome made from the product of two 3-digit numbers.
;;;左右どちらから読んでも同じ値になる数を回文数という。 2桁の数の積で表される回文数のうち、
;;;最大のものは 9009 = 91 × 99 である。
;;;では、3桁の数の積で表される回文数のうち最大のものはいくらになるか。
(ns projecteuler.problem-4
(:require [clojure.string :as str])
@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))
@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 / ja.org
Created November 16, 2012 11:50
A small rant about ClojureScript

みじかい ClojureScript のはなし

@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.