Created
January 5, 2013 04:50
-
-
Save tnoda/4459823 to your computer and use it in GitHub Desktop.
#mitori_clj Project Euler Problem 19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Joda Time、いいですね。そういえば最近日付関係の演算って業務でやってないな...。
これくらいシンプルだとあえて Clojure の wrapper を作るまでもないのでしょうが、自分は
filter
とかtake-while
とかの述語にカッコをなるべく付けないのが好きなので、tnoda さんのようにsunday?
とかtwentieth-century?
は多分自分も同じように作ってしまうのでしょうね。