-
-
Save natecook1000/601463d7353114b047da54dd34d8c9dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct I : Comparable { | |
let v: Int | |
static func <(lhs: I, rhs: I) -> Bool { return lhs.v < rhs.v } | |
static func ==(lhs: I, rhs: I) -> Bool { return lhs.v == rhs.v } | |
} | |
let source = repeatElement(1...1000, count: 1000).joined().map(I.init) | |
let n = 3 | |
func foo() -> Int { | |
var checksum = 0 | |
if CommandLine.arguments.first == "by" { | |
for _ in 1...n { | |
let sorted = source.sorted(by: <) | |
checksum += sorted.first!.v | |
} | |
} else { | |
for _ in 1...n { | |
let sorted = source.sorted() | |
checksum += sorted.first!.v | |
} | |
} | |
return checksum | |
} | |
print(foo()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment