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
import Foundation | |
final class URLProtocolMock: URLProtocol { | |
static var data = [URL: (error: Error?, data: Data?)]() | |
override class func canInit(with request: URLRequest) -> Bool { | |
return true | |
} | |
override class func canonicalRequest(for request: URLRequest) -> URLRequest { |
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
struct BigInt { | |
let string: String | |
func add(_ value: BigInt) -> BigInt { | |
if self.string == "0" { return value } | |
if value.string == "0" { return self } | |
var lhs = self.string | |
var rhs = value.string |
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
struct BigInt { | |
private let overflows: UInt64 | |
private var remainder: UInt64 | |
func add(_ x: BigInt) -> BigInt { | |
let totalOverflows = self.overflows + x.overflows | |
let result = self.remainder.addingReportingOverflow(x.remainder) | |
return BigInt( |
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
let res = Decimal(string: "9999999999999999999999999999999999999999999")! | |
* Decimal(string: "99999999999998999999999999999999999")! | |
print(res) // 999999999999989999999999999999999989990000000000000000000000000000000000000000 - wrong | |
// correct result – 999999999999989999999999999999999989999999900000000000001000000000000000000001 |
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
enum AoCDay13 { | |
static func solve() -> Int { | |
let pairs = input.split(separator: "\n\n") | |
.map { $0.split(separator: "\n") } | |
.map { (String($0[0]), String($0[1])) } | |
var sum = 0 | |
for (index, pair) in pairs.enumerated() { | |
print("====================== Pair \(index) ======================") | |
print("\(pair.0)\n\(pair.1)") |
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
// | |
// Matrix.swift | |
// SudokuSolver | |
// | |
// Created by Bohdan Savych on 19/4/22. | |
// | |
import Foundation | |
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
// | |
// MonadsExperimentations.swift | |
// Algorithms | |
// | |
// Created by Bohdan Savych on 23/10/2022. | |
// | |
import Foundation | |
precedencegroup CompositionPrecedence { |
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
// | |
// DI.swift | |
// MobiusNotes | |
// | |
// Created by bsavych on 05/08/2022. | |
// | |
import Foundation | |
enum DIScope { |
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
var dict = [Int: Int?]() | |
let val = dict[0] // Int?? | |
func f(_ optionalInt: Int?) -> Int { optionalInt ?? 0 } | |
//f(val) // compiler error | |
f(val.flatten()) // works |
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
protocol ActionDoable: AnyObject { | |
func doAction(with value: Int) | |
} | |
class A: ActionDoable { | |
func doAction(with value: Int) { | |
print("do from A \(value)") | |
} | |
} |
NewerOlder