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

Version Path
trackler-2.2.1.180 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.179 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.178 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.177 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.176 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.175 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.174 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.173 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.172 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.171 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.170 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.169 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.167 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.166 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.165 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.164 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.163 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.162 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.161 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.160 tracks/julia/exercises/difference-of-squares/example.jl