Skip to content

Instantly share code, notes, and snippets.

View tnoda's full-sized avatar

Takahiro Noda tnoda

View GitHub Profile
@kohyama
kohyama / pep011.clj
Last active December 10, 2015 04:28
Project Euler Problem 11
(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)
@kohyama
kohyama / pep024+.clj
Last active December 10, 2015 02:58
Project Euler Problem 24
(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))
@ponkore
ponkore / problem_11.clj
Created December 23, 2012 13:47
Project Euler Problem 11
;;; 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))
@emanon001
emanon001 / problem_13.clj
Last active December 10, 2015 01:18
Project Euler Problem 13 #mitori_clj
;;; 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
@plaster
plaster / pe-16.clj
Last active February 18, 2017 06:52
Project Euler Problem 16 solution in Clojure
;;;; 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)
@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
@kohyama
kohyama / pep017.clj
Created December 19, 2012 10:19
Project Euler Problem 17
(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"
@ypsilon-takai
ypsilon-takai / pe_4_other.clj
Created December 17, 2012 07:55
Project euler 4
;;ざっと思い付いたものを実装してみました。
;; 合っているかどうかも未検証 (12/17)
;;(12/17 21:00)
;; やっぱり考慮がまったく足りていなかったので、基本は変えずに全面みなおし。
(defn palindromic? [s]
(= (seq s) (reverse s)))
@emanon001
emanon001 / problem_6.clj
Created December 15, 2012 09:08
Project Euler Problem 6 #mitori_clj
;;; 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)))