Skip to content

Instantly share code, notes, and snippets.

@tnoda
Created January 5, 2013 04:50
Show Gist options
  • Save tnoda/4459823 to your computer and use it in GitHub Desktop.
Save tnoda/4459823 to your computer and use it in GitHub Desktop.
#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]
(= 7 (.getDayOfWeek dt)))
(defn- twentieth-century?
[^DateTime dt]
(= 20 (.getCenturyOfEra dt)))
(defn solver
[]
(->> (DateTime. 1901 1 1 0 0 (GregorianChronology/getInstance))
(iterate a-month-later)
(filter sunday?)
(take-while twentieth-century?)
count))
@ponkore
Copy link

ponkore commented Jan 9, 2013

Joda Time、いいですね。そういえば最近日付関係の演算って業務でやってないな...。
これくらいシンプルだとあえて Clojure の wrapper を作るまでもないのでしょうが、自分は filter とか take-while とかの述語にカッコをなるべく付けないのが好きなので、tnoda さんのように sunday? とか twentieth-century? は多分自分も同じように作ってしまうのでしょうね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment