This file contains hidden or 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
(require '[clojure.string :as s]) | |
(require '[clojure.test :refer (deftest run-tests is)]) | |
(defn trans [[& rows]] (apply (partial map list) rows)) | |
(defn flip [mat] (map reverse mat)) | |
(defn rot45 [mat] | |
(let [w (count (first mat)) | |
h (count mat) |
This file contains hidden or 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
(require '[clojure.test :refer (is)]) | |
(defn pms | |
"Permutations lexicographic by index." | |
[[a & [b & [c & _]] :as ls]] | |
(cond | |
(nil? a) '() | |
(nil? b) `(~a) | |
(nil? c) `((~a ~b) (~b ~a)) | |
:else (mapcat (fn [h] (map (fn [r] (cons h r)) |
This file contains hidden or 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
;;; 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)) |
This file contains hidden or 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
;;; 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 |
This file contains hidden or 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
;;;; 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)) |
This file contains hidden or 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
;;; 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) |
This file contains hidden or 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-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 |
This file contains hidden or 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
(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" |
This file contains hidden or 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
;;ざっと思い付いたものを実装してみました。 | |
;; 合っているかどうかも未検証 (12/17) | |
;;(12/17 21:00) | |
;; やっぱり考慮がまったく足りていなかったので、基本は変えずに全面みなおし。 | |
(defn palindromic? [s] | |
(= (seq s) (reverse s))) | |
This file contains hidden or 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
;;; Project Euler Problem 6 | |
;;; 「二乗の和と和の二乗の差はいくつか?」 | |
;;; http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%206 | |
(use 'clojure.test) | |
(defn sum-of-squares | |
"与えられた数列についてその二乗の和を返します" | |
[nums] | |
(apply + (map #(* % %) nums))) |