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
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 |
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 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" |
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 'cl) | |
(loop for x from 1 to 10000 | |
do (insert (format "Case %d: a = %s\n" | |
x (if (zerop (% x 2)) "False" "True")))) |
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
;; 逆 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 (-?>>)]) |
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
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)() |
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
// 辞書順で順列列挙 | |
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) { |
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
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); |
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
;; 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))] |
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
;; 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 の利き筋列挙" |
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
;; 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 |