Sha256: 6dc379198b475c5a68cee18ea5c45fee94d356dd4833ca8ef5ed4db83c21d82f

Contents?: true

Size: 487 Bytes

Versions: 396

Compression:

Stored size: 487 Bytes

Contents

struct Squares {

    var max = 1

    init (_ max: Int) {
        if max > 0 {
            self.max = max
        }
    }

    var squareOfSums: Int {
        let numbers = Array(1...self.max)
        let sum = numbers.reduce(0, + )
        return sum * sum
    }

    var sumOfSquares: Int {
        let numbers = Array(1...self.max)
        return numbers.map { return $0*$0 }.reduce(0, + )
    }

    var differenceOfSquares: Int {
        return squareOfSums - sumOfSquares
    }
}

Version data entries

396 entries across 396 versions & 1 rubygems

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