Решение на Първа задача от Симеон Цветков

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

Към профила на Симеон Цветков

Резултати

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

Код

class Integer
def prime?
(2..self-1).each do|i|
if self % i == 0
return false
end
end
if self < 1
return false
else
return true
end
end
def digits
digit = []
number = self
(number).each do |i|
digit[i] = number % 10
number = number / 10
end
return digit
end
end
p 9.digits

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

/tmp/d20131023-4395-1e8oun5/solution.rb:17:in `digits': undefined method `each' for 9:Fixnum (NoMethodError)
	from /tmp/d20131023-4395-1e8oun5/solution.rb:24:in `<top (required)>'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:867:in `require'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:867:in `block in setup_load_path_and_require'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:867:in `each'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:867:in `setup_load_path_and_require'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration_options.rb:25:in `configure'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:21:in `run'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in `run'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'

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

Симеон обнови решението на 16.10.2013 16:58 (преди около 11 години)

+class Integer
+ def prime?
+ (2..self-1).each do|i|
+ if self % i == 0
+ return false
+ else
+ return true
+ end
+ end
+ if self < 1 return false
+ elsif self == 1 || self == 2 return true
+ end
+ end
+ def digits
+ digit = []
+ number = self
+ (number).each do |i|
+ digit[i] = number % 10
+ number = number / 10
+ end
+ return digit
+ end
+end
+p 9.digits

Симеон обнови решението на 16.10.2013 17:05 (преди около 11 години)

class Integer
def prime?
(2..self-1).each do|i|
if self % i == 0
return false
- else
- return true
end
end
- if self < 1 return false
- elsif self == 1 || self == 2 return true
+ if self < 1
+ return false
+ else
+ return true
end
end
def digits
digit = []
number = self
(number).each do |i|
digit[i] = number % 10
number = number / 10
end
return digit
end
end
p 9.digits