Решение на Осма задача от Александрина Каракехайова

Обратно към всички решения

Към профила на Александрина Каракехайова

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 40 неуспешни тест(а)

Код

module Sheet
def fill_sheet(data, sheet, i, current)
while i < data.size
fill(data, sheet, current, i)
end
sheet << current
end
def fill(data, sheet, current,i)
last = data[i - 1]
if (data[i] == " " and last == " ") || data[i] == "\t" || data[i] == "\n"
sheet << current if current != " "
current, last, i = "", data[i], i + 1
else current, last, i = current + data[i],data[i], i + 1
end
end
def index_numbers(cell_index)
index_array, numbers = cell_index.chars, ""
while index_array.empty? == false
if index_array[0].ord > 47 && index_array[0].ord < 58
numbers += index_array[0]
end
index_array.shift
end
numbers
end
def transform(letters, index)
while letters.empty? == false
if letters.size == 1
index += letters[0].ord - 64
else index += 26 * (letters[0].ord - 64)
end
letters.shift
end
index
end
end
class Spreadsheet
include Sheet
attr_accessor :sheet, :data
def initialize(data = nil)
@data = data.strip if data
columns = count_columns(data)
temp = []
@sheet = fill_sheet(@data, temp, 1, @data[0]).each_slice(columns).to_a
end
def empty?
if @data == nil || @data == ""
true
else false
end
end
def cell_at(cell_index)
letters, numbers = index_letters(cell_index), index_numbers(cell_index)
letters = transform(letters.chars, 0)
@sheet[letters - 1][numbers - 1]
end
def []
end
def count_columns(sheet)
columns, index, previous = 1, 1, sheet[0]
while sheet[index] != "\n"
columns += 1 if sheet[index] == "\t"
columns += 1 if sheet[index] == " " and previous == " "
previous, index = sheet[index - 1], index + 1
end
columns
end
end

Лог от изпълнението

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) Spreadsheet#new can be called with no arguments or with a single string argument
     Failure/Error: Spreadsheet.new
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20160121-5693-12685uw/solution.rb:69:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:4:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:4:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Spreadsheet#new creates a blank sheet when no arguments are passed
     Failure/Error: expect(Spreadsheet.new).to be_empty
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20160121-5693-12685uw/solution.rb:69:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:10:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:10:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Spreadsheet#new creates a blank sheet when a blank string is passed
     Failure/Error: expect(Spreadsheet.new('')).to be_empty
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:14:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:14:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) Spreadsheet#new creates a non-empty sheet when a non-blank string is passed
     Failure/Error: expect(Spreadsheet.new('foo')).not_to be_empty
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:71:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:18:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:18:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) Spreadsheet#to_s returns blank tables as blank strings
     Failure/Error: expect(Spreadsheet.new.to_s).to eq ''
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20160121-5693-12685uw/solution.rb:69:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:24:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:24:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) Spreadsheet#to_s returns one-cell tables as a string
     Failure/Error: expect(Spreadsheet.new('foo').to_s).to eq 'foo'
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:28:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:28:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) Spreadsheet#to_s returns multi-cell, oneline tables as a string
     Failure/Error: expect(Spreadsheet.new("foo\tbar\tbaz").to_s).to eq "foo\tbar\tbaz"
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:32:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:32:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) Spreadsheet#to_s returns multi-cell, multiline tables as a string
     Failure/Error: expect(Spreadsheet.new("foo\tbar\nbaz\tlarodi").to_s).to eq "foo\tbar\nbaz\tlarodi"
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:11:in `fill'
     # /tmp/d20160121-5693-12685uw/solution.rb:4:in `fill_sheet'
     # /tmp/d20160121-5693-12685uw/solution.rb:48:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:36:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:36:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) Spreadsheet#to_s splits cells by two or more spaces
     Failure/Error: expect(Spreadsheet.new("foo  bar   42\nbaz    larodi  100").to_s).to eq "foo\tbar\t42\nbaz\tlarodi\t100"
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:14:in `fill'
     # /tmp/d20160121-5693-12685uw/solution.rb:4:in `fill_sheet'
     # /tmp/d20160121-5693-12685uw/solution.rb:48:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:40:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:40:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) Spreadsheet#to_s returns the evaluated spreadsheet as a table
     Failure/Error: sheet = Spreadsheet.new <<-TABLE
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:11:in `fill'
     # /tmp/d20160121-5693-12685uw/solution.rb:4:in `fill_sheet'
     # /tmp/d20160121-5693-12685uw/solution.rb:48:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:44:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:44:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) Spreadsheet#cell_at raises and exception for non-existant cells
     Failure/Error: expect { Spreadsheet.new('foo')['B10'] }.to raise_error(Spreadsheet::Error, /Cell 'B10' does not exist/)
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-12685uw/spec.rb:59:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) Spreadsheet#cell_at returns the raw value of existing cells
     Failure/Error: sheet = Spreadsheet.new <<-TABLE
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:11:in `fill'
     # /tmp/d20160121-5693-12685uw/solution.rb:4:in `fill_sheet'
     # /tmp/d20160121-5693-12685uw/solution.rb:48:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:63:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:63:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) Spreadsheet#[] raises an exception for non-existant cells
     Failure/Error: expect { Spreadsheet.new()['A1'] }.to raise_error(Spreadsheet::Error, /Cell 'A1' does not exist/)
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-12685uw/spec.rb:75:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  14) Spreadsheet#[] returns the value of existing cells for simple cell indexes
     Failure/Error: sheet = Spreadsheet.new <<-TABLE
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:14:in `fill'
     # /tmp/d20160121-5693-12685uw/solution.rb:4:in `fill_sheet'
     # /tmp/d20160121-5693-12685uw/solution.rb:48:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:79:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:79:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  15) Spreadsheet#[] returns the value of existing cells for complex cell indexes
     Failure/Error: sheet = Spreadsheet.new (["a#{"\tb" * 30}c"] * 20).join("\n")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:11:in `fill'
     # /tmp/d20160121-5693-12685uw/solution.rb:4:in `fill_sheet'
     # /tmp/d20160121-5693-12685uw/solution.rb:48:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:91:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:91:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  16) Spreadsheet#[] returns the calculated value of formulae cells
     Failure/Error: sheet = Spreadsheet.new "foo\tADD(2, 2)\t=ADD(2, 2)"
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:99:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:99:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  17) Spreadsheet#[] adds two numbers with ADD
     Failure/Error: sheet = Spreadsheet.new("=ADD(2, 2)")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:72:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:107:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:107:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  18) Spreadsheet#[] adds five numbers with ADD
     Failure/Error: sheet = Spreadsheet.new("=ADD(1, 2, 3, 4, 5)")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:113:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:113:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  19) Spreadsheet#[] raises an exception for less than two arguments passed to ADD
     Failure/Error: Spreadsheet::Error, /Wrong number of arguments for 'ADD': expected at least 2, got 1/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-12685uw/spec.rb:120:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  20) Spreadsheet#[] adds numbers from cell references and as immediate arguments with ADD
     Failure/Error: sheet = Spreadsheet.new("42  =ADD(1, A1, 2, C1)  10")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:72:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:129:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:129:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  21) Spreadsheet#[] adds numbers only from cell references with ADD
     Failure/Error: sheet = Spreadsheet.new("2  3  5  =ADD(B1, A1, C1)  20")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:135:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:135:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  22) Spreadsheet#[] multiplies numbers with MULTIPLY
     Failure/Error: sheet1 = Spreadsheet.new("=MULTIPLY(1, 2, 3, 4, 5)")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:141:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:141:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  23) Spreadsheet#[] raises an exception for less than two arguments to MULTIPLY
     Failure/Error: Spreadsheet::Error, /Wrong number of arguments for 'MULTIPLY': expected at least 2, got 1/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-12685uw/spec.rb:150:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  24) Spreadsheet#[] subtracts two numbers with SUBTRACT
     Failure/Error: sheet = Spreadsheet.new("=SUBTRACT(5, 3)  10")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:71:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:159:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:159:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  25) Spreadsheet#[] subtracts numbers via cell references
     Failure/Error: sheet = Spreadsheet.new("2  3  5  =SUBTRACT(C1, 1)  20")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:72:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:165:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:165:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  26) Spreadsheet#[] raises an exception when SUBTRACT is called with a wrong number of arguments
     Failure/Error: Spreadsheet::Error, /Wrong number of arguments for 'SUBTRACT': expected 2, got 1/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-12685uw/spec.rb:172:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  27) Spreadsheet#[] divides two numbers with DIVIDE
     Failure/Error: sheet = Spreadsheet.new("=DIVIDE(84, 2)  10")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:72:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:181:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:181:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  28) Spreadsheet#[] divides numbers via cell references
     Failure/Error: sheet1 = Spreadsheet.new("2  84  =DIVIDE(B1, A1)  20")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:187:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:187:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  29) Spreadsheet#[] raises an exception when DIVIDE is called with a wrong number of arguments
     Failure/Error: Spreadsheet::Error, /Wrong number of arguments for 'DIVIDE': expected 2, got 1/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-12685uw/spec.rb:196:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  30) Spreadsheet#[] calculates the modulo of two numbers with MOD
     Failure/Error: expect(Spreadsheet.new('=MOD(42, 5)')['A1']).to eq('2')
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:72:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:205:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:205:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  31) Spreadsheet#[] calculates the modulo of two numbers with MOD via cell references
     Failure/Error: sheet1 = Spreadsheet.new("10  84  =MOD(B1, A1)  20")
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:211:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:211:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  32) Spreadsheet#[] raises an exception when MOD is called with a wrong number of arguments
     Failure/Error: Spreadsheet::Error, /Wrong number of arguments for 'MOD': expected 2, got 1/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-12685uw/spec.rb:220:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  33) Spreadsheet#[] adds floating point numbers with ADD
     Failure/Error: expect(Spreadsheet.new('10  =ADD(A1, 1.1)')['B1']).to eq '11.10'
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:229:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:229:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  34) Spreadsheet#[] subtracts floating point numbers with SUBTRACT
     Failure/Error: expect(Spreadsheet.new('10  =SUBTRACT(A1, 1.1)')['B1']).to eq '8.90'
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:72:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:234:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:234:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  35) Spreadsheet#[] multiplies floating point numbers with MULTIPLY
     Failure/Error: expect(Spreadsheet.new('10  =MULTIPLY(A1, 1.1)')['B1']).to eq '11'
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:72:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:239:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:239:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  36) Spreadsheet#[] divides floating point numbers with DIVIDE
     Failure/Error: expect(Spreadsheet.new('10  =DIVIDE(A1, 4)')['B1']).to eq '2.50'
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:72:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:244:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:244:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  37) Spreadsheet#[] evaluates deeply-nested cell references
     Failure/Error: expect(Spreadsheet.new('10  =ADD(5, A1)  3  =DIVIDE(B1, C1)  =MOD(D1, 4)')['E1']).to eq '1'
     Timeout::Error:
       execution expired
     # /tmp/d20160121-5693-12685uw/solution.rb:70:in `count_columns'
     # /tmp/d20160121-5693-12685uw/solution.rb:46:in `initialize'
     # /tmp/d20160121-5693-12685uw/spec.rb:250:in `new'
     # /tmp/d20160121-5693-12685uw/spec.rb:250:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  38) Spreadsheet#[] raises an exception for unknown functions
     Failure/Error: Spreadsheet::Error, /Unknown function 'FOO'/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-12685uw/spec.rb:255:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  39) Spreadsheet#[] raises an exception for missing cells passed as function arguments
     Failure/Error: Spreadsheet::Error, /Cell 'B4' does not exist/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-12685uw/spec.rb:261:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  40) Spreadsheet#[] raises an exception for invalid expressions
     Failure/Error: Spreadsheet::Error, /Invalid expression 'FOO'/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-12685uw/spec.rb:267:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 30.14 seconds
40 examples, 40 failures

Failed examples:

rspec /tmp/d20160121-5693-12685uw/spec.rb:3 # Spreadsheet#new can be called with no arguments or with a single string argument
rspec /tmp/d20160121-5693-12685uw/spec.rb:9 # Spreadsheet#new creates a blank sheet when no arguments are passed
rspec /tmp/d20160121-5693-12685uw/spec.rb:13 # Spreadsheet#new creates a blank sheet when a blank string is passed
rspec /tmp/d20160121-5693-12685uw/spec.rb:17 # Spreadsheet#new creates a non-empty sheet when a non-blank string is passed
rspec /tmp/d20160121-5693-12685uw/spec.rb:23 # Spreadsheet#to_s returns blank tables as blank strings
rspec /tmp/d20160121-5693-12685uw/spec.rb:27 # Spreadsheet#to_s returns one-cell tables as a string
rspec /tmp/d20160121-5693-12685uw/spec.rb:31 # Spreadsheet#to_s returns multi-cell, oneline tables as a string
rspec /tmp/d20160121-5693-12685uw/spec.rb:35 # Spreadsheet#to_s returns multi-cell, multiline tables as a string
rspec /tmp/d20160121-5693-12685uw/spec.rb:39 # Spreadsheet#to_s splits cells by two or more spaces
rspec /tmp/d20160121-5693-12685uw/spec.rb:43 # Spreadsheet#to_s returns the evaluated spreadsheet as a table
rspec /tmp/d20160121-5693-12685uw/spec.rb:58 # Spreadsheet#cell_at raises and exception for non-existant cells
rspec /tmp/d20160121-5693-12685uw/spec.rb:62 # Spreadsheet#cell_at returns the raw value of existing cells
rspec /tmp/d20160121-5693-12685uw/spec.rb:74 # Spreadsheet#[] raises an exception for non-existant cells
rspec /tmp/d20160121-5693-12685uw/spec.rb:78 # Spreadsheet#[] returns the value of existing cells for simple cell indexes
rspec /tmp/d20160121-5693-12685uw/spec.rb:90 # Spreadsheet#[] returns the value of existing cells for complex cell indexes
rspec /tmp/d20160121-5693-12685uw/spec.rb:98 # Spreadsheet#[] returns the calculated value of formulae cells
rspec /tmp/d20160121-5693-12685uw/spec.rb:106 # Spreadsheet#[] adds two numbers with ADD
rspec /tmp/d20160121-5693-12685uw/spec.rb:112 # Spreadsheet#[] adds five numbers with ADD
rspec /tmp/d20160121-5693-12685uw/spec.rb:118 # Spreadsheet#[] raises an exception for less than two arguments passed to ADD
rspec /tmp/d20160121-5693-12685uw/spec.rb:128 # Spreadsheet#[] adds numbers from cell references and as immediate arguments with ADD
rspec /tmp/d20160121-5693-12685uw/spec.rb:134 # Spreadsheet#[] adds numbers only from cell references with ADD
rspec /tmp/d20160121-5693-12685uw/spec.rb:140 # Spreadsheet#[] multiplies numbers with MULTIPLY
rspec /tmp/d20160121-5693-12685uw/spec.rb:148 # Spreadsheet#[] raises an exception for less than two arguments to MULTIPLY
rspec /tmp/d20160121-5693-12685uw/spec.rb:158 # Spreadsheet#[] subtracts two numbers with SUBTRACT
rspec /tmp/d20160121-5693-12685uw/spec.rb:164 # Spreadsheet#[] subtracts numbers via cell references
rspec /tmp/d20160121-5693-12685uw/spec.rb:170 # Spreadsheet#[] raises an exception when SUBTRACT is called with a wrong number of arguments
rspec /tmp/d20160121-5693-12685uw/spec.rb:180 # Spreadsheet#[] divides two numbers with DIVIDE
rspec /tmp/d20160121-5693-12685uw/spec.rb:186 # Spreadsheet#[] divides numbers via cell references
rspec /tmp/d20160121-5693-12685uw/spec.rb:194 # Spreadsheet#[] raises an exception when DIVIDE is called with a wrong number of arguments
rspec /tmp/d20160121-5693-12685uw/spec.rb:204 # Spreadsheet#[] calculates the modulo of two numbers with MOD
rspec /tmp/d20160121-5693-12685uw/spec.rb:210 # Spreadsheet#[] calculates the modulo of two numbers with MOD via cell references
rspec /tmp/d20160121-5693-12685uw/spec.rb:218 # Spreadsheet#[] raises an exception when MOD is called with a wrong number of arguments
rspec /tmp/d20160121-5693-12685uw/spec.rb:228 # Spreadsheet#[] adds floating point numbers with ADD
rspec /tmp/d20160121-5693-12685uw/spec.rb:233 # Spreadsheet#[] subtracts floating point numbers with SUBTRACT
rspec /tmp/d20160121-5693-12685uw/spec.rb:238 # Spreadsheet#[] multiplies floating point numbers with MULTIPLY
rspec /tmp/d20160121-5693-12685uw/spec.rb:243 # Spreadsheet#[] divides floating point numbers with DIVIDE
rspec /tmp/d20160121-5693-12685uw/spec.rb:249 # Spreadsheet#[] evaluates deeply-nested cell references
rspec /tmp/d20160121-5693-12685uw/spec.rb:253 # Spreadsheet#[] raises an exception for unknown functions
rspec /tmp/d20160121-5693-12685uw/spec.rb:259 # Spreadsheet#[] raises an exception for missing cells passed as function arguments
rspec /tmp/d20160121-5693-12685uw/spec.rb:265 # Spreadsheet#[] raises an exception for invalid expressions

История (3 версии и 0 коментара)

Александрина обнови решението на 11.01.2016 13:10 (преди над 8 години)

+module Sheet
+ def fill_sheet(data, sheet, i, current)
+ while i < data.size
+ fill(data, sheet, current, i)
+ end
+ sheet << current
+ end
+
+ def fill(data, sheet, current,i)
+ last = data[i - 1]
+ if (data[i] == " " and last == " ") || data[i] == "\t" || data[i] == "\n"
+ sheet << current if current != " "
+ current, last, i = "", data[i], i + 1
+ else current, last, i = current + data[i],data[i], i + 1
+ end
+ end
+
+ def index_numbers(cell_index)
+ index_array, numbers = cell_index.chars, ""
+ while index_array.empty? == false
+ if index_array[0].ord > 47 && index_array[0].ord < 58
+ numbers += index_array[0]
+ end
+ index_array.shift
+ end
+ numbers
+ end
+
+ def transform(letters, index)
+ while letters.empty? == false
+ if letters.size == 1
+ index += letters[0].ord - 64
+ else index += 26 * (letters[0].ord - 64)
+ end
+ letters.shift
+ end
+ index
+ end
+end
+
+
+
+
+
+
+class Spreadsheet
+ include Sheet
+ attr_accessor :sheet, :data
+ def initialize(data = nil)
+ @data = data.strip if data
+ columns = count_columns(data)
+ @sheet = fill_sheet(@data, [], 1, @data[0]).each_slice(columns).to_a
+ end
+
+
+ def empty?
+ if @data == nil || @data == ""
+ true
+ else false
+ end
+ end
+
+ def cell_at(cell_index)
+ letters, numbers = index_letters(cell_index), index_numbers(cell_index)
+ letters = transform(letters.chars, 0)
+ @sheet[letters - 1][numbers - 1]
+ end
+
+ def []
+ end
+
+ def count_columns(sheet)
+ columns, index, previous = 1, 1, sheet[0]
+ while sheet[index] != "\n"
+ columns += 1 if sheet[index] == "\t"
+ columns += 1 if sheet[index] == " " and previous == " "
+ previous, index = sheet[index - 1], index + 1
+ end
+ columns
+ end
+end

Александрина обнови решението на 11.01.2016 13:18 (преди над 8 години)

module Sheet
def fill_sheet(data, sheet, i, current)
while i < data.size
- fill(data, sheet, current, i)
+ fill(data, sheet, current, i)
end
sheet << current
end
def fill(data, sheet, current,i)
- last = data[i - 1]
- if (data[i] == " " and last == " ") || data[i] == "\t" || data[i] == "\n"
- sheet << current if current != " "
- current, last, i = "", data[i], i + 1
- else current, last, i = current + data[i],data[i], i + 1
- end
+ last = data[i - 1]
+ if (data[i] == " " and last == " ") || data[i] == "\t" || data[i] == "\n"
+ sheet << current if current != " "
+ current, last, i = "", data[i], i + 1
+ else current, last, i = current + data[i],data[i], i + 1
+ end
end
def index_numbers(cell_index)
index_array, numbers = cell_index.chars, ""
while index_array.empty? == false
if index_array[0].ord > 47 && index_array[0].ord < 58
numbers += index_array[0]
end
index_array.shift
end
numbers
end
def transform(letters, index)
while letters.empty? == false
if letters.size == 1
index += letters[0].ord - 64
else index += 26 * (letters[0].ord - 64)
end
letters.shift
end
index
end
end
-
-
-
-
-
class Spreadsheet
include Sheet
attr_accessor :sheet, :data
def initialize(data = nil)
@data = data.strip if data
columns = count_columns(data)
@sheet = fill_sheet(@data, [], 1, @data[0]).each_slice(columns).to_a
end
def empty?
if @data == nil || @data == ""
true
else false
end
end
def cell_at(cell_index)
letters, numbers = index_letters(cell_index), index_numbers(cell_index)
letters = transform(letters.chars, 0)
@sheet[letters - 1][numbers - 1]
end
def []
end
def count_columns(sheet)
columns, index, previous = 1, 1, sheet[0]
while sheet[index] != "\n"
columns += 1 if sheet[index] == "\t"
columns += 1 if sheet[index] == " " and previous == " "
previous, index = sheet[index - 1], index + 1
end
columns
end
end

Александрина обнови решението на 11.01.2016 13:46 (преди над 8 години)

module Sheet
def fill_sheet(data, sheet, i, current)
while i < data.size
fill(data, sheet, current, i)
end
sheet << current
end
def fill(data, sheet, current,i)
last = data[i - 1]
if (data[i] == " " and last == " ") || data[i] == "\t" || data[i] == "\n"
sheet << current if current != " "
current, last, i = "", data[i], i + 1
else current, last, i = current + data[i],data[i], i + 1
end
end
def index_numbers(cell_index)
index_array, numbers = cell_index.chars, ""
while index_array.empty? == false
if index_array[0].ord > 47 && index_array[0].ord < 58
numbers += index_array[0]
end
index_array.shift
end
numbers
end
def transform(letters, index)
while letters.empty? == false
if letters.size == 1
index += letters[0].ord - 64
else index += 26 * (letters[0].ord - 64)
end
letters.shift
end
index
end
end
class Spreadsheet
include Sheet
attr_accessor :sheet, :data
def initialize(data = nil)
@data = data.strip if data
columns = count_columns(data)
- @sheet = fill_sheet(@data, [], 1, @data[0]).each_slice(columns).to_a
+ temp = []
+ @sheet = fill_sheet(@data, temp, 1, @data[0]).each_slice(columns).to_a
end
def empty?
if @data == nil || @data == ""
true
else false
end
end
def cell_at(cell_index)
letters, numbers = index_letters(cell_index), index_numbers(cell_index)
letters = transform(letters.chars, 0)
@sheet[letters - 1][numbers - 1]
end
def []
end
def count_columns(sheet)
columns, index, previous = 1, 1, sheet[0]
while sheet[index] != "\n"
columns += 1 if sheet[index] == "\t"
columns += 1 if sheet[index] == " " and previous == " "
previous, index = sheet[index - 1], index + 1
end
columns
end
end