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.159 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.158 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.157 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.156 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.155 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.154 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.153 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.152 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.151 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.150 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.149 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.148 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.147 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.146 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.145 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.144 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.143 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.142 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.141 tracks/julia/exercises/difference-of-squares/example.jl
trackler-2.2.1.140 tracks/julia/exercises/difference-of-squares/example.jl