01/11(水) 2012
適度にミスタイプする
class String def getpos s=self.size rand(s) end def wrongone n=1 pos=getpos res=self.dup res[pos]=res[pos]+1 puts pos if $DEBUG res end def getposx r=self pos1=getpos(r.size-1) pos1=getpos(r.size-1) until not r[pos1]==r[pos1+1] pos2=pos1+1 [pos1,pos2] end def trrt r=self.dup pos1,pos2=getposx tmp=r[pos2] r[pos2]=r[pos1] r[pos1]=tmp r end def wxy u=self.dup (rand(2)+1).times{u=u.wrongone} u end def wrr u=self.dup pos=getpos if pos==0 u=u[pos..pos]+u[pos..-1] else u=u[0..pos-1]+u[pos..pos]+u[pos..-1] end u end def wg u=self.dup pos=getpos(u.size-1) if pos==0 u[pos+1..-1] else u[0..pos-1]+u[pos+1..-1] end end def wrongrand case rand(2) when 0 wrr when 1 rand>0.5 ? trrt : rand>0.5 ? wg : wxy end end def wrong r=self.dup r=r.wrongrand r= rand>0.5 ? r : r.wrongrand (r= rand>0.5 ? r : r.wrongrand) while r==self r end def wrongpercent c rand(100)<c ? wrong : self end end if __FILE__ == $0 str=ARGV[0] || "qwertyuiop" cent=ARGV[1] || 50 cent=cent.to_i n=1000 n.times{|i|puts "#{i} #{str.wrongpercent(cent)}"} end
コメント
トラックバック - http://rubyist.g.hatena.ne.jp/hatecha/20120111
カレンダー
- PyCrypto:GAE : ローカルだと動かない。 - Windows Live
- Google App Engine Blog: App Engine SDK 1.3.5 Released With New Task Queue, Python Precompilation, and Blob Features
- 線形回帰モデルとか - Standard ML of Yukkuri
- Czajkowski ? Blog Archive ? LoCo Directory Meeting
- The Best Web Development Frameworks
- 2010-06-30 - Webと文字
- Android アプリケーションを強制終了させる ? BPS株式会社 開発ブログ Beyond Perspective Solutions LTD.
- Python cookbook - Google ブックス
- Herald Tribune (HeraldTribune) on Twitter
- Ajaxian ? jQuery.fn.webkitTransform: bananas on the skew-whiff
- rst2pdfの日本語周り設定 - typeof(undefined)
- twoauth/oauth.py at master from techno’s python-twoauth - GitHub
- TRANSLATION LOG トマス・ピンチョン 1973全米図書賞授賞式 を翻訳する
- App Engine: Entity life cycle webhooks in the Datastore admin interface
- win-django.com - 複数のmodelを結合する 1