Sha256: 245911babb5e2d1e2ac34b7dbfaf1b5393f6466968bedf2d0a44f6622af03d37
Contents?: true
Size: 943 Bytes
Versions: 325
Compression:
Stored size: 943 Bytes
Contents
#if os(Linux) import Glibc #elseif os(OSX) import Darwin #endif extension Int { init(_ value: Trinary) { self = value.toDecimal } } struct Trinary { private var stringValue = "" fileprivate var toDecimal: Int = 0 private func isValidTrinary() -> Bool { return (Int(stringValue) ?? -1) > -1 ? true : false } private func tri2int(_ input: String) -> Int { let orderedInput = Array(input.characters.reversed()) let enumarated = orderedInput.enumerated() var tempInt: Int = 0 for (inx, each) in enumarated { let tempCharInt = Int("\(each)") ?? 0 let tempTriPower = Int(pow(Double(3), Double(inx))) tempInt += tempTriPower * tempCharInt } return tempInt } init( _ sv: String) { self.stringValue = sv if isValidTrinary() { self.toDecimal = tri2int(sv) } } }
Version data entries
325 entries across 325 versions & 1 rubygems