Ruby

RTA時間計測ツール:rta.rb

RTAのチェックポイントごとのタイムの記録を取るのを楽にするツールを作りましたので公開します。 (ただし、このツールを使ってお使いのコンピュータに不具合が生じても責任を取ることはできませんのであしからず。) 使い方 まず、チェックポイント一覧を…

直積

class Array def cartesian_product top = shift if empty? top else c = cartesian_product top.inject [] do |r, i| c.each do |j| r.push [i, *j] end r end end end end dice = [1,2,3,4,5,6] puts [dice, dice].cartesian_product.map {|i| "(#{i.join …

冪集合

Rubyで配列の冪集合を返すメソッド。 class Array def powerset power = [] bits = Array.new(self.length){|i| 2**i } (0..2**self.length-1).each do |i| s = [] bits.map{|j| j & i }.each_with_index do |item, index| s.push self[index] unless item =…

closure

d:id:syou6162:20080728で > hoge <- "hogehoge" > (function(){cat(hoge,fill=T)})() hogehoge が動くのが気持ち悪いと書いてある。lambdaも同じだからなぁ、私はこれ気にならないというか、慣れると便利というか、lambdaかわいいよlambdaというか(ぉ私も…

円を作ってみた

(define (make-circle radius) (let rows ((r 0) (row '())) (if (= r (+ (* 2 radius) 1)) (reverse row) (rows (+ r 1) (cons (let columns ((c 0) (col '())) (if (= c (+ (* 2 radius) 1)) (reverse col) (columns (+ c 1) (cons (if (> (magnitude (mak…

集中を要する作業のお供に

るびまをほぼパクって以下のようなものを作ってみました。 #!/usr/bin/ruby -Ku require 'webrick' require 'webrick/httpproxy' require 'uri' handler = Proc.new {|req,res| res.body.gsub!(/.*/m, '') } s = WEBrick::HTTPProxyServer.new(:BindAddress …

お茶の時間

今日のは何の役にも立たないネタです。オチもありません。 (use srfi-1) (define -> lambda) (map (->(x) (* x x)) (iota 10)) ; (0 1 4 9 16 25 36 49 64 81) (ヒント:Ruby 1.9で->はlambda)lambdaを楽に書きたい人にはいいのかも。私は普段だったら…や…

タブ区切りテキストをtabularに変換

こんなんあると便利かも、と思って作った自作ツールなのですが、実際に使用頻度も高いので試しに公開してみます。 タブでコラムを区切っている形式の表が記述されているテキストファイルのパスを引数にこのスクリプトを呼ぶと、その表をtexの表に変換し、標…