Sha256: 5d5ffe110bd76429573aedfc9fae9b9d8b99b8024fdcde9034c1a18d4eac22cc
Contents?: true
Size: 453 Bytes
Versions: 318
Compression:
Stored size: 453 Bytes
Contents
# This uses reduce instead of sum because sum can't handle empty collections properly. # There is no universal zero-element, so it has to be specified manually and cannot # be determined automatically. Otherwise, n=0 will cause an error. sum_of_squares(n::Int) = reduce(+, 0, i^2 for i in 1:n) # However, sum{T<:Real}(r::Range{T}) can handle "empty" ranges. square_of_sum(n::Int) = sum(1:n)^2 difference(n::Int) = square_of_sum(n) - sum_of_squares(n)
Version data entries
318 entries across 318 versions & 1 rubygems