Hello! In the RUBY code It throws an error, the sum method was not found, or how best to do it ... Thanks | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hello! In the RUBY code It throws an error, the sum method was not found, or how best to do it ... Thanks

A row measuring n units in length has red blocks with a minimum length of m units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square. Let the fill-count function, F(m, n), represent the number of ways that a row can be filled. For example, F(3, 29) = 673135 and F(3, 30) = 1089155. That is, for m = 3, it can be seen that n = 30 is the smallest value for which the fill-count function first exceeds one million. In the same way, for m = 10, it can be verified that F(10, 56) = 880711 and F(10, 57) = 1148904, so n = 57 is the least value for which the fill-count function first exceeds one million. For m = 50, find the least value of n for which the fill-count function first exceeds one million. https://code.sololearn.com/c8pskR4MsRWp/?ref=app

11th Mar 2020, 9:25 AM
Альберт
5 Answers
+ 3
Can you share your code so that we can check?
11th Mar 2020, 9:30 AM
A͢J
A͢J - avatar
+ 2
Альберт This is not right way to do sum. In ruby we use sum like this. [1, 2, 3, 4].sum #10 or ['foo', 'bar'].sum #foobar check this link to know how we can implement sum method in Ruby https://blog.bigbinary.com/2016/11/02/ruby-2-4-introduces-enumerable-sum.html
11th Mar 2020, 9:34 AM
A͢J
A͢J - avatar
+ 1
Альберт Check this how to work with sum and array in Ruby. l,m,v=100000,50,[1] n = Array.new p = 0 while v[-1] < l p = [m, v[-1]].sum n[v[-1]] = p v[-1] = v[-1] + 1 end puts m, n.length - 2, l if you print p in loop it will print 51, 52, 53, 54 and so on.
11th Mar 2020, 10:08 AM
A͢J
A͢J - avatar
0
Write not find method sum
11th Mar 2020, 9:36 AM
Альберт
0
Thanks for your help
11th Mar 2020, 10:56 AM
Альберт