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.5.13 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.12 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.11 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.10 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.9 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.8 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.7 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.6 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.5 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.4 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.3 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.2 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.1 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.5.0 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.4.0 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.3.9 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.3.8 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.3.7 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.3.6 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift
trackler-2.0.3.5 tracks/swift/exercises/perfect-numbers/PerfectNumbersExample.swift