Skip to content

Instantly share code, notes, and snippets.

View Sharrp's full-sized avatar

Anton Vronskii Sharrp

  • Tokyo, Japan
View GitHub Profile
@Sharrp
Sharrp / gist:84a7862c04531fc2e5a6
Last active August 29, 2015 14:14
Next number with the same digits
// 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]
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
}
}