Sha256: f65a8931cbd00cc883b843dd453eea471216618733fc0d3483645506d8d4b674

Contents?: true

Size: 1.32 KB

Versions: 362

Compression:

Stored size: 1.32 KB

Contents

import Foundation

enum SublistKind {

    case sublist
    case superlist
    case equal
    case unequal

}
func classifier(listOne: [Int], listTwo: [Int]) -> SublistKind {

    if  listOne == listTwo {

        return .equal
    } else if listOne.isEmpty || listTwo.isEmpty {

        if listOne.isEmpty {

            return .sublist
        }
        return .superlist

    } else if listOne.count != listTwo.count {

        var i = 0
        var count = 0
        var smallerList = [Int]()

        var iterations = 0
        iterations = max(listOne.count, listTwo.count) - (min(listOne.count, listTwo.count) - 1)

        while iterations > 0 {

            var j = i
            while count <= min(listOne.count, listTwo.count) - 1 {

                if listOne.count > listTwo.count {

                    smallerList.append(listOne[j])

                } else {

                    smallerList.append(listTwo[j])
                }

                j+=1
                count+=1
            }

            if smallerList == listTwo {

                return .superlist

            } else if smallerList == listOne {

                return .sublist

            } else {

                smallerList.removeAll()
                i+=1
                count = 0
            }

            iterations-=1

        }

    }
    return .unequal
}

Version data entries

362 entries across 362 versions & 1 rubygems

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