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 int1 = BigInt(value: "34757377374573285823949593499549646311234") | |
| let int2 = BigInt(value: "45123498348958923845838948528381283721377123454345") | |
| let product = int1 * int2 | |
| // result: 1568374460575699918065222772187576926314538959488859994856690985365041943440429553059611730 |
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
| import UIKit | |
| import Foundation | |
| struct BigInt { | |
| var value: String | |
| func multiply(right: BigInt) -> BigInt { | |
| var leftCharacterArray = value.characters.reversed().map { Int(String($0))! } | |
| var rightCharacterArray = right.value.characters.reversed().map { Int(String($0))! } |
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 * (left: BigInt, right: BigInt) -> BigInt { return left.multiply(right) } |
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 multiply(right: BigInt) -> BigInt { | |
| var a1 = value.characters.reversed().map { Int(String($0))! } | |
| var a2 = right.value.characters.reversed().map { Int(String($0))! } | |
| ... | |
| ... | |
| // And change the last line | |
| return BigInt(value: result.map { String($0) }.joined(separator: "")) | |
| } |
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
| struct BigInt { | |
| var value: String | |
| func multiply(right: String) -> String { | |
| // We'll change this line to use `value` | |
| var leftCharacterArray = value.characters.reversed().map { Int(String($0))! } | |
| var rightCharacterArray = right.characters.reversed().map { Int(String($0))! } | |
| ... |
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 int1 = BigInt("10") | |
| let int2 = BigInt("5") | |
| let product = int1 * int2 |
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 multiply(left: String, right: String) -> String { | |
| var leftCharacterArray = left.characters.reversed().map { Int(String($0))! } | |
| var rightCharacterArray = right.characters.reversed().map { Int(String($0))! } | |
| var result = [Int](repeating: 0, count: leftCharacterArray.count+rightCharacterArray.count) | |
| for leftIndex in 0..<leftCharacterArray.count { | |
| for rightIndex in 0..<rightCharacterArray.count { | |
| let resultIndex = leftIndex + rightIndex | |
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
| struct BigInt { | |
| var value: String | |
| } |
NewerOlder