読者です 読者をやめる 読者になる 読者になる

Verbal Arithmetic (#128)

class VerbalArithmetic def initialize(expr) parse(expr) analys end attr_reader :factor, :sum, :table private def parse(expr) term = expr.scan(/\w+/) unless expr.count('=') == 1 && (expr.count('+') + 2) == term.length raise AugmentError, "s…

Magic Squares (#124)

奇数のみ class OddMagicSquare attr_reader :square, :order def initialize(order) @order = order @square = case when order % 2 == 1 then odd_order else make_square(@order) end end def show @square ? @square.map {|l| l.join(",") }.join("\n") …

Huffman Encoder (#123)

回答 # Ruby Quiz Huffman Encoder #123 module Enumerable def stable_sort_by(&block) i = 0 self.sort_by {|v| [block.call(v), i+=1]} end end class HuffmanEncoder def initialize(data) freq = Hash.new data.split(//).each do |c| freq[c] = 0 unle…

[http://d.hatena.ne.jp/nappa_zzz/20070429:title]

こんなもんでよいのかな。 # Ruby Quiz #122 # checking credit card # class CreditCard def initialize(number) @number = number nomalize = number.gsub(/\s/,"") @type = check_type(nomalize) @valid = check_valid(nomalize) end def valid? @valid e…