Skip to content

Instantly share code, notes, and snippets.

View CPiersigilli's full-sized avatar

Cesare Piersigilli CPiersigilli

  • C. Piersigilli & Associati
  • Italy
View GitHub Profile
@kieranb662
kieranb662 / SwiftEquationSolvers.md
Last active March 13, 2023 18:01
[Polynomial Solvers] A set of polynomial equation solvers written in Swift. #Math

Swift Equation Solvers

Most equations need to be solved numerically since no close-form expression representing their solutions can be obtained. For polynomial equations of order 1, 2, 3, 4 exact solutions can be obtained. I have created a series of solvers up to a cubic solver, that can be used to obtain most exact solutions. Of course with floating point errors, not everything is going to come out looking clean. To be able to handle complex numbers I made a simplified version of a complex number without all the mathematical operations.

If you call the cubicSolve function with a = 0 then the solver falls back on the quadratic solver, the quadratic solver will fallback on the linear solver and linear solver will return an empty array(Thanks for catching that u\korbonix).

Example Usage

@AvdLee
AvdLee / MutableProgress.swift
Last active February 13, 2024 10:05
Adding children to a Progress instance is easy, but removing is not possible by default. This could have been useful when you want to use a single Progress instance which can have different children over time. Using this custom class MutableProgress makes this possible. See: https://www.avanderlee.com/general/controlling-progress-children/
import UIKit
/// An additional class build on top of `Progress` to make it possible to also remove children from progress.
public final class MutableProgress: Progress {
public override var totalUnitCount: Int64 {
get {
return Int64(children.count)
}
set {
@brennanMKE
brennanMKE / Async.swift
Last active March 6, 2023 13:01
Blocking with Semaphores and DispatchGroups in Swift
import PlaygroundSupport
import Foundation
class Worker {
private let queue = DispatchQueue.global(qos: .background)
private let serialQueue = DispatchQueue(label: "com.acme.serial")
public private(set) var count = 0
func incrementCount() {