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

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

Към профила на Пепа Симеонова

Резултати

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

Код

Integer#prime?
unless self == 1 or self == 0
(((2 ** self) - 2) % self == 0)? true : false
end
end
Integer#prime_factors
i=2; temp = self; factors = []
while i<=temp
while i.prime? and temp % i == 0
temp=temp/i; factors.push i
end
i+=1
end
return factors
end
class Integer
def harmonic
temp = self
def help_func(n,sum)
if n == 0
sum
else
help_func(n-1, sum += 1/n)
end
end
return help_func(temp,0)
end
end
class Integer
def digits
temp = self
digits_array = []
while temp > 0
digits_array.push( temp%10 )
temp = temp/10
end
return digits_array.reverse
end
end
class Array
def average
sum = 0
size_array = self.size
self.each { |x| sum += x}
return sum/size_array
end
end
class Array
def drop_every n
new_array = []; i = 1
while i < self.size
if i % n != 0
new_array.push(self[i-1])
end
i += 1
end
return new_array
end
end
Array#define combine_with(other)
i = 0; combined_array = []; max_size = [self.size , other.size]
for i in 0..max_size.max
i>=self.size ? combined_array.push(self[i]) : next
i>=other.size ? combined_array.push(other[i]) : next
end
return combined_array
end

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

/data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:867:in `require': /tmp/d20131023-4395-1huqr3r/solution.rb:5: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)
	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'

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

Пепа обнови решението на 16.10.2013 12:37 (преди около 11 години)

+Integer#prime?
+ unless self == 1 or self == 0
+ (((2 ** self) - 2) % self == 0)? true : false
+ end
+end
+
+Integer#prime_factors
+ i=2; temp = self; factors = []
+ while i<=temp
+ while i.prime? and temp % i == 0
+ temp=temp/i; factors.push i
+ end
+ i+=1
+ end
+ return factors
+end
+
+class Integer
+ def harmonic
+ temp = self
+ def help_func(n,sum)
+ if n == 0
+ sum
+ else
+ help_func(n-1, sum += 1/n)
+ end
+ end
+ return help_func(temp,0)
+ end
+end
+
+class Integer
+ def digits
+ temp = self
+ digits_array = []
+ while temp > 0
+ digits_array.push( temp%10 )
+ temp = temp/10
+ end
+ return digits_array.reverse
+ end
+ end
+
+
+class Array
+ def average
+ sum = 0
+ size_array = self.size
+ self.each { |x| sum += x}
+ return sum/size_array
+ end
+end
+
+
+class Array
+ def drop_every n
+ new_array = []; i = 1
+ while i < self.size
+ if i % n != 0
+ new_array.push(self[i-1])
+ end
+ i += 1
+ end
+ return new_array
+end
+end
+
+
+Array#define combine_with(other)
+ i = 0; combined_array = []; max_size = [self.size , other.size]
+ for i in 0..max_size.max
+ i>=self.size ? combined_array.push(self[i]) : next
+
+ i>=other.size ? combined_array.push(other[i]) : next
+ end
+ return combined_array
+end
+