Решение на Осма задача от Емилия Банчева

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

Към профила на Емилия Банчева

Резултати

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

Код

module Functions
def count_rows(data)
counter, counter_char = 0, 0
while counter_char < data.length()
if data[counter_char] == '\n'
counter = counter + 1
end
counter_char = counter_char + 1
end
counter
end
def count_columns(data)
character, counter = 0, 0
if data[character] == '\t' or data[counter_char] == " "
counter = counter + 1 while data[counter_char] != '\n'
character += 1
end
counter
end
def get_row(char)
letters, counter = ("A..Z").to_a, 0
while char[counter] != nil
counter += 1 while char[counter] != letters[counter]
counter += 1
counter
end
end
def is_letter?(symbol)
counter, letters = 0, ("A..Z").to_a
counter += 1 while letters[counter] != symbol and counter == 26
counter += 1
true ? counter == 27 : false
end
def is_index?(symbols)
counter = 0
while symbol[counter] != nil
counter += 1 while symbols[counter].is_letter? == false
false if symbols[counter + 1] == '='
true if symbols[counter + 1].integer? == true
end
end
def get_answer(question)
case question[0..1]
when "AD" then add(question[3..question.length()])
when "MU" then multiply(question[8..question.length()])
when "SU" then subtract(question[8..question.length()])
when "DI" then divide(question[6..question.length()])
when "MO" then mod(question[3..question.length()])
end
end
end
class Spreadsheet
include Functions
def initialize(data = nil)
if data == nil
@sheet = Matrix.build(0, 0)
else
@sheet = Matrix(count_rows, count_columns)
end
end
def empty?
true ? @sheet == Matrix.empty(0, 0) : false
end
def cell_at(index)
# @sheet.[](get_row(index[0]), index[1]) if index.length == 2
sum, counter, counter_numbers = 0, 0, 0
counter += 1 while index[counter].integer? == false
numbers = get_row(index[0..counter]).to_a
sum += (numbers[counter_numbers] * 26) while counter_numbers != counter
# @sheet.[]((sum + numbers[counter]), (index[(counter + 1)..index.length()]))
end
def add(numbers)
sum, index, counter = 0, 0, 0
if numbers[0].integer? == true
counter += 1 and index += 1 while numbers[index] != '+'
sum += numbers[index] if numbers[index]
end
end
def [](index)
@sheet.cell_at if index.is_index? == true
counter, length = 0, index.length()
counter += 1 while index[counter].is_letter? == true
if index[counter + 1] == '='
index[(counter + 2)..length] if index[counter + 2].integer? == true
get_answer(index[(counter + 2)..length])
end
end
end

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

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) Spreadsheet#new can be called with no arguments or with a single string argument
     Failure/Error: Spreadsheet.new
     NameError:
       uninitialized constant Spreadsheet::Matrix
     # /tmp/d20160121-5693-17lvfmy/solution.rb:56:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:4:in `new'
     # /tmp/d20160121-5693-17lvfmy/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
     NameError:
       uninitialized constant Spreadsheet::Matrix
     # /tmp/d20160121-5693-17lvfmy/solution.rb:56:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:10:in `new'
     # /tmp/d20160121-5693-17lvfmy/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
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:14:in `new'
     # /tmp/d20160121-5693-17lvfmy/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
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:18:in `new'
     # /tmp/d20160121-5693-17lvfmy/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 ''
     NameError:
       uninitialized constant Spreadsheet::Matrix
     # /tmp/d20160121-5693-17lvfmy/solution.rb:56:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:24:in `new'
     # /tmp/d20160121-5693-17lvfmy/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'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:28:in `new'
     # /tmp/d20160121-5693-17lvfmy/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"
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:32:in `new'
     # /tmp/d20160121-5693-17lvfmy/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"
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:36:in `new'
     # /tmp/d20160121-5693-17lvfmy/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"
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:40:in `new'
     # /tmp/d20160121-5693-17lvfmy/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
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:44:in `new'
     # /tmp/d20160121-5693-17lvfmy/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-17lvfmy/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
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:63:in `new'
     # /tmp/d20160121-5693-17lvfmy/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-17lvfmy/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
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:79:in `new'
     # /tmp/d20160121-5693-17lvfmy/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")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:91:in `new'
     # /tmp/d20160121-5693-17lvfmy/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)"
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:99:in `new'
     # /tmp/d20160121-5693-17lvfmy/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)")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:107:in `new'
     # /tmp/d20160121-5693-17lvfmy/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)")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:113:in `new'
     # /tmp/d20160121-5693-17lvfmy/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-17lvfmy/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")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:129:in `new'
     # /tmp/d20160121-5693-17lvfmy/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")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:135:in `new'
     # /tmp/d20160121-5693-17lvfmy/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)")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:141:in `new'
     # /tmp/d20160121-5693-17lvfmy/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-17lvfmy/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")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:159:in `new'
     # /tmp/d20160121-5693-17lvfmy/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")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:165:in `new'
     # /tmp/d20160121-5693-17lvfmy/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-17lvfmy/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")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:181:in `new'
     # /tmp/d20160121-5693-17lvfmy/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")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:187:in `new'
     # /tmp/d20160121-5693-17lvfmy/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-17lvfmy/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')
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:205:in `new'
     # /tmp/d20160121-5693-17lvfmy/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")
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:211:in `new'
     # /tmp/d20160121-5693-17lvfmy/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-17lvfmy/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'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:229:in `new'
     # /tmp/d20160121-5693-17lvfmy/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'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:234:in `new'
     # /tmp/d20160121-5693-17lvfmy/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'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:239:in `new'
     # /tmp/d20160121-5693-17lvfmy/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'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:244:in `new'
     # /tmp/d20160121-5693-17lvfmy/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'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-17lvfmy/solution.rb:2:in `count_rows'
     # /tmp/d20160121-5693-17lvfmy/solution.rb:58:in `initialize'
     # /tmp/d20160121-5693-17lvfmy/spec.rb:250:in `new'
     # /tmp/d20160121-5693-17lvfmy/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-17lvfmy/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-17lvfmy/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-17lvfmy/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 0.03353 seconds
40 examples, 40 failures

Failed examples:

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

История (1 версия и 2 коментара)

Емилия обнови решението на 11.01.2016 17:09 (преди над 8 години)

+module Functions
+ def count_rows(data)
+ counter, counter_char = 0, 0
+ while counter_char < data.length()
+ if data[counter_char] == '\n'
+ counter = counter + 1
+ end
+ counter_char = counter_char + 1
+ end
+ counter
+ end
+ def count_columns(data)
+ character, counter = 0, 0
+ if data[character] == '\t' or data[counter_char] == " "
+ counter = counter + 1 while data[counter_char] != '\n'
+ character += 1
+ end
+ counter
+ end
+ def get_row(char)
+ letters, counter = ("A..Z").to_a, 0
+ while char[counter] != nil
+ counter += 1 while char[counter] != letters[counter]
+ counter += 1
+ counter
+ end
+ end
+ def is_letter?(symbol)
+ counter, letters = 0, ("A..Z").to_a
+ counter += 1 while letters[counter] != symbol and counter == 26
+ counter += 1
+ true ? counter == 27 : false
+ end
+ def is_index?(symbols)
+ counter = 0
+ while symbol[counter] != nil
+ counter += 1 while symbols[counter].is_letter? == false
+ false if symbols[counter + 1] == '='
+ true if symbols[counter + 1].integer? == true
+ end
+ end
+ def get_answer(question)
+ case question[0..1]
+ when "AD" then add(question[3..question.length()])
+ when "MU" then multiply(question[8..question.length()])
+ when "SU" then subtract(question[8..question.length()])
+ when "DI" then divide(question[6..question.length()])
+ when "MO" then mod(question[3..question.length()])
+ end
+ end
+end
+class Spreadsheet
+ include Functions
+ def initialize(data = nil)
+ if data == nil
+ @sheet = Matrix.build(0, 0)
+ else
+ @sheet = Matrix(count_rows, count_columns)
+ end
+ end
+ def empty?
+ true ? @sheet == Matrix.empty(0, 0) : false
+ end
+ def cell_at(index)
+ # @sheet.[](get_row(index[0]), index[1]) if index.length == 2
+ sum, counter, counter_numbers = 0, 0, 0
+ counter += 1 while index[counter].integer? == false
+ numbers = get_row(index[0..counter]).to_a
+ sum += (numbers[counter_numbers] * 26) while counter_numbers != counter
+ # @sheet.[]((sum + numbers[counter]), (index[(counter + 1)..index.length()]))
+ end
+ def add(numbers)
+ sum, index, counter = 0, 0, 0
+ if numbers[0].integer? == true
+ counter += 1 and index += 1 while numbers[index] != '+'
+ sum += numbers[index] if numbers[index]
+ end
+ end
+ def [](index)
+ @sheet.cell_at if index.is_index? == true
+ counter, length = 0, index.length()
+ counter += 1 while index[counter].is_letter? == true
+ if index[counter + 1] == '='
+ index[(counter + 2)..length] if index[counter + 2].integer? == true
+ get_answer(index[(counter + 2)..length])
+ end
+ end
+end

На двата коментирани реда във функцията cell_at ми даваше грешка "Spaces around operators * no spaces around [] on line 65 * no spaces around [] on line 70", която не можах да разбера точно как да се справя с нея затова ги коментирах. Ако може да ми кажете какъв е бил проблема и как се решава. Благодаря!

@Емилия, извинявам се, че сме пропуснали да ти отговорим на този коментар.

Правилният запис на въпросните редове е следният:

# Bad - your version
@sheet.[](get_row(index[0]), index[1]) if index.length == 2

# Good - conventional usage
@sheet[get_row(index[0]), index[1])] if index.length == 2