Sha256: 1ad62a96141b950abdcdc23f44f337b2b55b0c0ea29d0dab53c6ded9cbf32bdf

Contents?: true

Size: 738 Bytes

Versions: 130

Compression:

Stored size: 738 Bytes

Contents

enum NumberClassification {
    case perfect
    case abundant
    case deficient
}

struct NumberClassifier {
    let number: Int
    var sum: Int {
        return aliquotSum(number)
    }
    var classification: NumberClassification {
        switch sum {
        case let sum where sum == number :
            return NumberClassification.perfect
        case let sum where sum < number :
            return NumberClassification.deficient
        default:
            return NumberClassification.abundant
        }
    }
    func aliquotSum (_ input: Int) -> Int {
        let array = Array(1..<(input-1))

        return array.filter({input % $0 == 0}).reduce(0, +)
    }

    init(number: Int) {
        self.number = number
    }

}

Version data entries

130 entries across 130 versions & 1 rubygems

Version Path
trackler-2.0.8.30 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.29 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.28 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.27 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.26 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.24 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.23 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.22 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.21 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.20 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.19 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.18 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.17 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.16 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.15 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.14 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.13 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.12 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.11 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift
trackler-2.0.8.10 tracks/swift/exercises/perfect-numbers/Sources/PerfectNumbersExample.swift