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.98 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.97 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.96 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.95 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.94 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.93 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.92 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.91 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.90 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.89 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.88 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.87 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.86 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.85 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.84 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.83 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.82 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.81 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.80 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift
trackler-2.2.1.79 tracks/swift/exercises/difference-of-squares/Sources/DifferenceOfSquaresExample.swift