Sha256: 9fc47559e526808babd471880bf0dc0fad05674f20847adff40185f6c47ff239

Contents?: true

Size: 375 Bytes

Versions: 180

Compression:

Stored size: 375 Bytes

Contents

module BookKeeping
  VERSION = 3
end

class Squares
  attr_reader :max

  def initialize(max)
    @max = max
  end

  def square_of_sum
    sum = 0
    (1..max).each do |i|
      sum += i
    end
    sum**2
  end

  def sum_of_squares
    sum = 0
    (1..max).each do |i|
      sum += i**2
    end
    sum
  end

  def difference
    square_of_sum - sum_of_squares
  end
end

Version data entries

180 entries across 180 versions & 1 rubygems

Version Path
trackler-2.1.0.24 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.23 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.22 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.21 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.20 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.19 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.18 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.17 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.16 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.15 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.14 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.13 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.12 tracks/ruby/exercises/difference-of-squares/.meta/solutions/difference_of_squares.rb
trackler-2.1.0.11 tracks/ruby/exercises/difference-of-squares/example.rb
trackler-2.1.0.10 tracks/ruby/exercises/difference-of-squares/example.rb
trackler-2.1.0.9 tracks/ruby/exercises/difference-of-squares/example.rb
trackler-2.1.0.8 tracks/ruby/exercises/difference-of-squares/example.rb
trackler-2.1.0.7 tracks/ruby/exercises/difference-of-squares/example.rb
trackler-2.1.0.6 tracks/ruby/exercises/difference-of-squares/example.rb
trackler-2.1.0.5 tracks/ruby/exercises/difference-of-squares/example.rb