Skip to content

Instantly share code, notes, and snippets.

View tnoda's full-sized avatar

Takahiro Noda tnoda

View GitHub Profile
;;;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_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
@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_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 / 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)))]
;; 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 / HelloWorld.java
Created February 2, 2013 07:42
MIxed-source Leiningen project example.
public class HelloWorld {
public static void helloWorld() {
System.out.println("Hello, world!");
}
}
require 'rake'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
@tnoda
tnoda / DrillOne.scala
Created April 3, 2013 10:46
[再帰ドリル](https://github.com/kazu-yamamoto/recursion-drill) を Scala で書いてみる.
package recfun
object DrillOne {
// sum of arithmetic progression
def soap(x: Int): Int =
if (x == 0) 0
else soap(x - 1) + x
// factorial
def fact(x: Int): Int =
(defun shibayu36/chomp (str)
(replace-regexp-in-string "[\n\r]+$" "" str))
(defun anything-git-project-project-dir ()
(shibayu36/chomp
(shell-command-to-string "git rev-parse --show-toplevel")))
(defun anything-c-sources-git-project-for ()
(loop for elt in
'(("Modified files (%s)" . "--modified")