Clojureを仕事で使った経験をメモしておきます。 2015年の冬に本番稼働したシステムのため、使用したライブラリ等については、必ずしも現在の流行に沿っていないと思います。
- スタッフがウェブブラウザによりアクセスし、ログインして使用する業務システム
- 商品管理、売上管理、支払管理etc..
- DBテーブル数80程度
- 画面数200程度
(defn treductions [f] | |
(fn [xf] | |
(let [last-val (volatile! ::none)] | |
(fn | |
([] (xf)) | |
([result] (xf result)) | |
([result input] | |
(if (= ::none @last-val) | |
(vreset! last-val input) | |
(vreset! last-val (f @last-val input))) |
(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 |
(ns euler.problem011 | |
(:require [clojure.string :as string])) | |
(defn parse-numbers | |
[input] | |
(for [line (->> (string/split-lines input) | |
(map #(re-seq #"\d+" %))) | |
:when (not-empty line)] | |
(map #(Long/parseLong %) line))) |
;;; In the 20x20 grid below, four numbers along a diagonal line have been marked in red. | |
;;; : | |
;;; (snip) | |
;;; : | |
;;; The product of these numbers is 26 * 63 * 78 * 14 = 1788696. | |
;;; What is the greatest product of four adjacent numbers | |
;;; in any direction (up, down, left, right, or diagonally) in the 20x20 grid? | |
(ns projecteuler.problem-11 | |
(:use clojure.test)) |
;;; Project Euler Problem 13 | |
;;; 「50桁の数字100個の和の上位10桁を求めよ」 | |
;;; http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2013 | |
(ns projecteuler-answers.problem-013 | |
(:require [clojure.math.numeric-tower :as math] | |
[clojure.test :refer [are]])) | |
(def nums | |
[37107287533902102798797998220837590246510135740250 |
;;;; Project Euler Problem 16 solution | |
;;;; http://projecteuler.net/problem=16 | |
(use 'clojure.test) | |
(import 'java.math.BigInteger) | |
;; Character/digit usage from: https://gist.github.com/4276901 | |
(def solve | |
(comp (partial apply +) | |
(partial map #(Character/digit ^char % 10)) |
;;; Project Euler #15 | |
;;; http://projecteuler.net/problem=15 | |
;;; http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2015 | |
(require '[clojure.test :refer [deftest is]]) | |
(defn fact | |
[n] | |
(loop [n n r 1] | |
(if (zero? n) |
(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 |
(require '[clojure.test :refer (is)]) | |
(defn in-words | |
"Represents the given number in English words without spaces nor hyphens. | |
This works with a number in the range from 1 to 1000" | |
[n] | |
(cond | |
(< n 20) | |
(["" "one" "two" "three" "four" "five" "six" "seven" "eight" | |
"nine" "ten" "eleven" "twelve" "thirteen" "fourteen" |