[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Fwd: Please Forward: Ruby Quiz Submission

James Gray

10/14/2007 3:14:00 PM

Begin forwarded message:

> From: "Vasil Vangelovski" <vvangelovski@gmail.com>
> Date: October 13, 2007 8:31:19 PM CDT
> To: submission@rubyquiz.com
> Subject: Please Forward: Ruby Quiz Submission
>
> #!/usr/bin/env ruby
> #
> #-------------------------------------------------------
> #
> # A very simple and extremely inefficient solution
> # for Ruby Quiz #143
> #
> #-------------------------------------------------------
> # Created by Vasil Vangelovski on 2007-10-14.
> # Copyright (c) 2007. All rights reserved.
>
> class String
> MIN =32
> MAX=126
> #incrementing in base 128, funny characters are skipped
> def increment
> new_one = self
> (new_one.size-1).downto(0) do |index|
> if new_one[index].to_i < MAX
> new_one[index]=(new_one[index].to_i + 1).chr
> return new_one
> end
> if (new_one[index].to_i == MAX)
> new_one[index]=MIN.chr
> end
> end
> return MIN.chr.to_s + self
> end
> end
>
> class Regexp
> #better to use this method for testing
> def printout(maxlength=5)
> stringus = " "
> while stringus.size <= maxlength
> puts stringus if (self.match(stringus) != nil)
> stringus = stringus.increment
> end
> end
> end
>
> /abe|cde|dfg/.printout(3)