This file contains hidden or 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 mergeSort<T: Comparable>(_ A : inout [T]) -> [T] { | |
if A.count == 2 { | |
if A[0] > A[1] { return [A[1], A[0]] } else { | |
return [A[0], A[1]] | |
} | |
This file contains hidden or 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 solution(_ A : inout [Int]) -> Int { | |
if A.count <= 3 { return 0 } | |
// write your code in Swift 3.0 (Linux) | |
// handle special cases | |
var toRight: [Int] = Array(repeating: 0, count: A.count - 2) | |
var toLeft: [Int] = Array(repeating: 0, count: A.count - 2) | |
for (index, _) in A.enumerated() { |
This file contains hidden or 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
func primeFactor(n: Int) -> [Int] { | |
var i: Int = 2 | |
var A: [Int] = Array(repeating: 0, count: n - 1) | |
var result: [Int] = [] | |
while i < n/2 { | |
var counter: Int = 0 | |
var index: Int = i * i + i * counter - 2 |
This file contains hidden or 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
// | |
// NetworkManager.swift | |
// DAC-Tracker | |
// | |
// Created by Arash K. on 2017-10-19. | |
// Copyright © 2017 Arash K. All rights reserved. | |
// | |
import Foundation |
This file contains hidden or 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
class Authentication: NSObject, KnowsRootViewController, SFSafariViewControllerDelegate { | |
static let shared = Authentication() | |
private static let clientId: String = "666" | |
private static let clientSecret: String = "777777" | |
private static let loginURL = URL(string: "https://github.com/login/oauth/authorize?scope=user:email&client_id=\(Authentication.clientId)")! | |
private static let logoutURL = URL(string: "https://github.com/logout")! | |
This file contains hidden or 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
typealias PageInfo = (page: Int16, perPage: Int16) | |
class SwiftyCollectionCell: UICollectionViewCell { | |
var row: Int16 = 0 | |
} | |
extension Collection where Iterator.Element == SwiftyCollectionCell { | |
func pageInfo(total: Int16 = Int16.max) -> PageInfo? { |
This file contains hidden or 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
func binarySearch(item: Int, in A: [Int]) -> Int? { | |
var beg = 0 | |
var end = A.count - 1 | |
var result: Int? | |
while end - beg >= 1 { | |
var mid = (beg + end) / 2 | |
This file contains hidden or 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
infix operator --> :AdditionPrecedence | |
func --><InputA, CompA, CompB>(first: @escaping ( InputA, @escaping (CompA?) -> () ) -> (), | |
second: @escaping ( CompA, @escaping (CompB?) -> () ) -> ()) -> (InputA, @escaping (CompB?) -> ()) -> () { | |
return { (input: InputA, compB: @escaping (CompB?) -> () ) in | |
first(input, { compA in | |
guard let validCompaA = compA else { compB(nil); return } |
This file contains hidden or 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
// | |
// AsynchronousOperation.swift | |
// | |
// Created by Vasily Ulianov on 09.02.17. | |
// Copyright © 2017 Vasily Ulianov. All rights reserved. | |
// | |
import Foundation | |
/// Subclass of `Operation` that add support of asynchronous operations. |