Skip to content

Instantly share code, notes, and snippets.

@natecook1000
Created January 8, 2017 01:41
Show Gist options
  • Save natecook1000/601463d7353114b047da54dd34d8c9dd to your computer and use it in GitHub Desktop.
Save natecook1000/601463d7353114b047da54dd34d8c9dd to your computer and use it in GitHub Desktop.
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