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
(defn remainders | |
[n m] | |
(let [r (rem n m)] | |
(lazy-seq (cons r (remainders (* r 10) m))))) | |
(defn distance-of-same-value-elements | |
[xs] | |
(loop [i 0, dict {}, xs xs] | |
(let [x (first xs)] | |
(if-let [j (get dict x)] |
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
#light | |
(* 次のような考え方で解きました。 | |
割り算の筆算を考えると、小数部が循環するのは、余りが循環しているからである。 | |
割り算の筆算と同じ計算手順を踏みながら計算途中にあらわれる、余りをチェックして | |
行けばよい。もし以前と同じ余りが出現したら、それ以降は過去と同じ計算が行われる | |
ことになるので、算出される小数部は循環する。 | |
つまり、筆算の余りに同じものが現れるまでの計算回数が、循環小数の循環部の長さである。 |
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
#light | |
type System.String with | |
member s.split (sep : char) = s.Split([|sep|]) |> Array.toList | |
let parseNumbersPyramid (s : string) = | |
[for x in (s.split '\n') -> x.Trim().split ' ' |> List.map int] | |
let greaters xs = | |
Seq.map2 max xs (List.tail xs) |
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
;;; fs-mono.el --- A Helper of fsharp-mode (v0.3) for Mono | |
(require 'cl) | |
(add-to-list 'load-path "~/.emacs.d/site-lisp/fsharp-mode") | |
(add-to-list 'auto-mode-alist '("\\.fs[iylx]?$" . fsharp-mode)) | |
(require 'fsharp) | |
(autoload 'run-fsharp "inf-fsharp" "Run an inferior F# process." t) |
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
(defn N->A [n] | |
(let [za "0ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
alen (dec (count za)) | |
iter (fn [[n xs]] [(int (/ n alen)) | |
(cons (nth za (rem n alen)), xs)])] | |
(->> (iterate iter [n '()]) | |
(drop-while (comp not zero? first)) | |
first second | |
(apply str)))) |
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
(def alpha "ABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
(def alen (count alpha)) | |
(defn freq-alpha [n] | |
(mapcat (partial repeat n) alpha)) | |
(defn fun [[xss m]] | |
[(map cons (freq-alpha m) (cycle xss)), (* m alen)]) |
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
// gmpxx : mpz_class で三項演算子が使えない(解決した) | |
#include <iostream> | |
#include <gmpxx.h> | |
// これなら OK | |
// mpz_class next_collatz(const mpz_class &n){ | |
// if(n % 2 == 0){ | |
// return n >> 1; | |
// }else{ | |
// return n * 3 + 1; |
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
select | |
sys.tables.name as table_name, | |
sys.extended_properties.value as discription, | |
sys.columns.name as column_name, | |
sys.columns.* | |
from sys.columns | |
left outer join sys.tables on (sys.columns.object_id=sys.tables.object_id) | |
left outer join sys.extended_properties on (major_id=sys.columns.object_id and minor_id=sys.columns.column_id) | |
where sys.tables.name is not null | |
order by table_name, sys.columns.column_id |
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
(defn- diff-seq | |
"Returns a lazy seq of numbers in s1 but not in s2. | |
Both of s1 and s2 must be increasing monotonically and infinite sequence." | |
[s1 s2] | |
(let [x1 (first s1), x2 (first s2)] | |
(cond | |
(= x1 x2) (recur (rest s1) (rest s2)) | |
(> x1 x2) (recur s1 (drop-while (partial > x1) s2)) | |
(< x1 x2) (let [[s1a s1b] (split-with (partial > x2) s1)] | |
(lazy-cat s1a (diff-seq s1b s2)))))) |
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
(defn- diff-seq | |
"Returns a lazy seq of numbers in s1 but not in s2. | |
Both of s1 and s2 must be increasing monotonically and infinite sequence." | |
[s1 s2] | |
(let [x1 (first s1), x2 (first s2)] | |
(cond | |
(= x1 x2) (recur (rest s1) (rest s2)) | |
(> x1 x2) (recur s1 (drop-while (partial > x1) s2)) | |
(< x1 x2) (let [[s1a s1b] (split-with (partial > x2) s1)] | |
(lazy-cat s1a (diff-seq s1b s2)))))) |