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
// Find the first number greater than given, made up with the same digits | |
// 0 - lowest digit in input array of digits | |
func nextNumber(digits: [Int]) -> [Int] | |
{ | |
var next = digits | |
for i in 1..<next.count | |
{ | |
if next[i] < next[i-1] // First descending order | |
{ | |
// Find the first greater than next[i] |
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
public func attempt<T>(source source: String = __FUNCTION__, file: String = __FILE__, line: Int = __LINE__, closure: () throws -> T) -> Optional<T>{ | |
do { | |
return try closure() | |
} catch { | |
let fileName = (file as NSString).lastPathComponent | |
let report = "Error \(fileName):\(source):\(line):\n \(error)" | |
print(report) | |
return nil | |
} | |
} |