Skip to content

Instantly share code, notes, and snippets.

@mnzk
mnzk / lazy_read.py
Created September 11, 2012 13:18
lazy read
import sys
def read(filename):
with open(filename) as f:
for line in f:
yield line
if __name__ == '__main__':
for line in read(sys.argv[1]):
print line
@mnzk
mnzk / make-coll.clj
Created May 27, 2012 06:23
make-coll.clj
(defn make-coll
[c n init]
(let [s (repeat n init)]
(if (instance? String c)
(apply str s)
(into (empty c) s))))
(make-coll [] 5 'a) ;=> [a a a a a]
(make-coll '() 5 'a) ;=> (a a a a a)
(make-coll "" 5 'a) ;=> "aaaaa"
@mnzk
mnzk / evenodd.el
Created May 26, 2012 14:03
evenodd.el
(require 'cl)
(loop for x from 1 to 10000
do (insert (format "Case %d: a = %s\n"
x (if (zerop (% x 2)) "False" "True"))))
@mnzk
mnzk / inv-fizzbuzz.clj
Created May 17, 2012 15:56
inv-fizzbuzz.clj
;; 逆 FizzBuzz
;; ------------------------------------------------
;; :dependencies [[org.clojure/clojure "1.4.0"]
;; [org.clojure/core.incubator "0.1.0"]
;; [org.clojure/math.numeric-tower "0.0.1"]]
;; -------------------------------------------------
(ns inv-fizzbuzz.core
(:use [clojure.core.incubator :only (-?>>)])
@mnzk
mnzk / sample_wpf.py
Created May 12, 2012 11:03
sample_wpf.py
from __future__ import print_function
import wpf
from System.Windows import Application
from System.Windows import Window
flip = lambda f, a: lambda b: f(b, a)
props = {'__init__' : flip(wpf.LoadComponent, 'w.xaml')}
win = type('', (Window,),props)()
@mnzk
mnzk / ExPermutations2.cs
Created April 24, 2012 14:19
ExPermutations2.cs
// 辞書順で順列列挙
using System;
using System.Linq;
using System.Collections.Generic;
static class Ex {
private static IEnumerable<IEnumerable<T>[]> __MoveRtoL<T>(IEnumerable<T> e1, IEnumerable<T> e2) {
while(e2.Count() > 0) {
@mnzk
mnzk / ExPermutations.cs
Created April 23, 2012 13:13
ExPermutations.cs
using System;
using System.Linq;
using System.Collections.Generic;
static class Ex {
public static IEnumerable<IEnumerable<T>> RotationsL<T>(this IEnumerable<T> xs) {
for(int i = xs.Count(); i > 0; i--) {
yield return xs;
xs = xs.Concat(xs.Take(1)).Skip(1);
@mnzk
mnzk / atcoder-q001-d.clj
Created April 18, 2012 12:51
atcoder-q001-d.clj
;; AtCoder 過去問 : 001-D 【レースゲーム】
;; http://arc001.contest.atcoder.jp/tasks/arc001_4
(defn- read-input
[]
(letfn [(read-num-pair
[] (->> (clojure.string/split (read-line) #"\s+")
(map #(Long/parseLong %))))
(read-num-pairs
[n] (repeatedly n read-num-pair))]
@mnzk
mnzk / atcoder-q001-c.clj
Created April 17, 2012 15:40
atcoder-q001-c.clj
;; AtCoder 過去問 : 001-C 【パズルのお手伝】
;; http://arc001.contest.atcoder.jp/tasks/arc001_3
(use '[clojure.set :only (difference)])
(use '[clojure.math.combinatorics :only (permutations)])
(def ^{:private true} r8 (range 1 9))
(defn accession-pos-set
"座標 x y に置かれた Q の利き筋列挙"
@mnzk
mnzk / atcoder-q001-b.clj
Created April 15, 2012 10:35
atcoder-q001-b.clj
;; AtCoder 過去問 : 001-B 【リモコン】
;; http://arc001.contest.atcoder.jp/tasks/arc001_2
(defn- q001-b*
[A B]
(letfn [(loop- [a b d acc xs]
(cond
(zero? d) acc
(empty? xs) (+ acc d)
:else (let [[x & xs] xs