Ruby - Enumerable - reduce

Sort by

recency

|

118 Discussions

|

  • + 0 comments
    #NEVER DO THIS
    class Object
    	Bignum=Integer
    	Fixnum=Integer
    end
    
    def sum_terms(n)
    	1.upto(n).inject(0) {|sum, n| sum + n**2 + 1}
    end
    
  • + 0 comments

    what a terrible challenge. This is the most complicated way of doing n**2 + 1 given that the input is n=25

  • + 0 comments
    Fixnum = Integer
    Bignum = Integer
    
    def sum_terms(n)
        1.upto(n).inject(0) {|sum, n| sum + n**2 + 1} 
    end
    
  • + 0 comments

    No matter what I try, including the posted solutions, I get some error related to Fixnum and Bignum. The proposed fix for this error doesn't work, either.

  • + 5 comments

    The

    uninitialized constant Fixnum (NameError)

    error is being caused by a hidden line of code which checks that we return a Fixnum or Bignum only. Unfortunately, these classes have not existed since Ruby 2.4+.

    I hope the challenge will be updated soon. In the meantime... the error can be fixed by adding the following code at the beginning of your submission:

    Fixnum = Integer
    Bignum = Integer
    

    Cheers!