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 Foundation | |
| let n = readLine()!.components(separatedBy: [" "]).map { Int($0)! } | |
| let (a, b) = (n[0], n[1]) | |
| for _ in 0..<b { | |
| for _ in 0..<a { | |
| print("*", terminator: "") | |
| } | |
| print() |
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 solution(_ x:Int, _ n:Int) -> [Int64] { | |
| let result = Array<Int>.init(repeating: 0, count: n) | |
| var index = 0 | |
| return result.map { (_) -> Int64 in | |
| index += 1 | |
| return Int64(index*x) | |
| } | |
| } |
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 solution(_ arr1:[[Int]], _ arr2:[[Int]]) -> [[Int]] { | |
| var i = 0, j = 0 | |
| return arr1.map { (numbers) -> [Int] in | |
| defer { | |
| i += 1 | |
| j = 0 | |
| } | |
| return numbers.map { (number) -> Int in | |
| defer { |
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 solution(_ phone_number:String) -> String { | |
| var index = 0 | |
| return String(Array(phone_number).map { (character) -> Character in | |
| defer { | |
| index += 1 | |
| } | |
| if index < phone_number.count-4 { | |
| return "*" | |
| } |
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 solution(_ x:Int) -> Bool { | |
| let sum = String(x).reduce(0) { (result, character) -> Int in | |
| result + (Int(String(character)) ?? 0) | |
| } | |
| return x % sum == 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 solution(_ arr:[Int]) -> Double { | |
| return Double(arr.reduce(0) { (result, number) -> Int in | |
| result + number | |
| })/Double(arr.count) | |
| } |
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 solution(_ num:Int) -> Int { | |
| func calculateCount(_ count: Int, _ inputNumber: Int) -> Int { | |
| if count > 500 { | |
| return -1 | |
| } | |
| if inputNumber == 1 { | |
| return count | |
| } | |
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 solution(_ n:Int, _ m:Int) -> [Int] { | |
| let gcd: Int | |
| let lcm: Int | |
| func calculateGCD(_ n: Int, _ m: Int) -> Int { | |
| if m == 0 { | |
| return n | |
| } | |
| return calculateGCD(m, n%m) |
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 solution(_ num:Int) -> String { | |
| return num%2 == 0 ? "Even" : "Odd" | |
| } |
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 solution(_ arr:[Int]) -> [Int] { | |
| var array = arr | |
| array.remove(at: array.firstIndex(of: array.min() ?? array[0])!) | |
| return array == [] ? [-1] : array | |
| } |