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
| @UIApplicationMain | |
| class AppDelegate: UIResponder, UIApplicationDelegate { | |
| var window: UIWindow? | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
| let k = DispatchSpecificKey<String>() | |
| DispatchQueue.main.setSpecific(key: k, value: "MainQ") | |
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
| let sessionConfiguration: URLSessionConfiguration = .default | |
| let proxyConfiguration: [AnyHashable : Any] = [ | |
| kCFNetworkProxiesHTTPEnable as AnyHashable: true, | |
| kCFNetworkProxiesHTTPPort as AnyHashable: [Place-proxy's-port-number-here], | |
| kCFNetworkProxiesHTTPProxy as AnyHashable: "Place-your-proxy-address-here" | |
| ] | |
| sessionConfiguration.connectionProxyDictionary = proxyConfiguration |
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
| extension String { | |
| extension String { | |
| func toArray() -> [Character] { | |
| return Array(characters) | |
| } | |
| #if swift(>=4) | |
| #else | |
| var count: Int { |
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 struct Queue<T> : CustomStringConvertible where T : CustomStringConvertible { | |
| fileprivate var array = [T]() | |
| public var description: String { | |
| var desc: String = "" | |
| desc = array.reduce(into: desc) { | |
| $0 += $1.description + "\n" | |
| } | |
| return desc | |
| } |
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
| for (a, b) in zip(A.enumerated(), B.enumerated()) { | |
| print("a[\(a.offset)]: \(a.element)") | |
| print("b[\(b.offset)]: \(b.element)") | |
| } |
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
| extension FloatingPoint { | |
| var isInt: Bool { | |
| #if swift(>=4.0) | |
| return self.truncatingRemainder(dividingBy: 1) == 0 | |
| #else | |
| return self % 1 == 0 | |
| #endif | |
| } | |
| } |
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 baseToDecimal(_ base: Int, notation : [Int]) -> Int { | |
| return notation.reversed().enumerated().filter { $0.element == 1 }.reduce(into: 0) { | |
| let powR = Int(pow(Float(base), Float($1.offset))) | |
| $0 += powR | |
| } | |
| } | |
| func decimal(_ d : Int, toBase base: Int) -> [Int] { | |
| var res = [Int]() |
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
| //https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md | |
| func modifying<T>(_ value: inout T, _ function: (inout T) -> ()) { | |
| function(&value) | |
| } | |
| modifying(&object.pair) { pair in swap(&pair.x, &pair.y) } |
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
| extension Array where Element : Comparable { | |
| var invertedIndexes: [(index: Index, value: Element)] { | |
| var res = [(index: Index, value: Element)]() | |
| for (k, v) in enumerated() { | |
| res.append((index: k, value: v)) | |
| } | |
| return res | |
| } | |
| } |
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
| # Create array from lines of separated values such as 1 2 3 | |
| arr = list(map(int, input().strip().split(' '))) | |
| import sys | |
| def read_in(): | |
| return [x.strip() for x in sys.stdin] | |
| lines = read_in() | |
| print(lines) |