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
// | |
// Fraction.swift | |
// | |
// Created by David Koontz on 8/28/23. | |
// | |
import Foundation | |
// Wonder if a Rational Fraction class would be valuable in Swift. | |
// - Use Int to model the numerator & denominator |
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
//Trying out a prefix operator | |
//I thought vertical elipses made sense, representative of rbg | |
prefix operator ⋮ | |
prefix func ⋮(hex:UInt32) -> Color { | |
return Color(hex) | |
} | |
extension Color { | |
init(_ hex: UInt32, opacity:Double = 1.0) { | |
let red = Double((hex & 0xff0000) >> 16) / 255.0 |
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 | |
// Inspired by https://gist.github.com/mbuchetics/c9bc6c22033014aa0c550d3b4324411a | |
struct JSONCodingKeys: CodingKey { | |
var stringValue: String | |
init?(stringValue: String) { | |
self.stringValue = stringValue | |
} |
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
// Use an integer literal to instantiate | |
let a: BigInt = 23559821412349283 | |
// Or use a string literal if you want to start with a number that is greater than IntMax | |
let b: BigInt = "123456789876543234567876543234567876543" | |
// Perform arithmetic operations | |
let c: BigInt = 123456 + 321 // -> 12777 | |
let d = c / 100 // -> 127 | |
let e = d << d // -> 12700000000......(127 zeros) |