반응형

Codewars(알고리즘) 25

[Codewars] [6Kyu] Consecutive Strings

Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 이번 문제는 String Array(strarr)와 k(Int, 조합할 갯수)값이 주어집니다. 그리고 strarr의 element들을 k만큼 각각 합쳤을 때 가장 긴 String을 반환하는 문제입니다. 이 문제의 하단에 제약조건이 모두 있는데, n=0, k > n, k String { guard strarr.count != 0 else { return "" } guard..

[Codewars] [7Kyu] Count the Digit

Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 이번 문제는 n과 d가 입력되고, n을 2제곱 한 값 에서 d가 포함된 갯수를 카운트 하는 문제입니다. 1. Swift 1-1. 본인의 풀이 func nbDig(_ n: Int, _ d: Int) -> Int { var returnValue: String = "" for k in 0 ... n { returnValue.append(String(k * k)) } retur..

[Codewars] [6Kyu] How Much?

Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 이번 문제는 m에서 n 사이의 값에서 9개의 c(cars)와 7개의 b(boats)를 갖고 있을 때 총 갖고 있던 값(M)과 b와 c의 각각의 값(B, C)을 구해서 반환하는 문제입니다. 1. Swift 1-1. 본인의 풀이 먼저 예제에 따라 값을 확인해 보겠습니다. m과 n이 각각 1, 100이기 때문에 1~100 사이의 값을 이용하게 됩니다. 그리고 그 값들 중에서 ..

[Codewars] [8Kyu] Switch it Up!

Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 이번 문제는 Int로 받은 값에 대해서 String으로 반환해주는 문제입니다. 1. Swift 1-1. 본인의 풀이 let numArr : [String] = [ "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" ] func switchItUp(_ number: Int) -> St..

[Codewars] [7Kyu] ToLeetSpeak

Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 이번 문제는 입력된 String을 대치시켜서 다시 String으로 반환하는 문제입니다. 1. Swift 1-1. 본인의 풀이 func toLeetSpeak(_ s : String) -> String { let leetSpeakArr : [Character : Character] = [ "A" : "@", "B" : "8", "C" : "(", "D" : "D", "E" ..

[Codewars] [7Kyu] Sum of odd numbers

Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 이번 문제는 연속된 홀수 값들을 피라미드로 만들고, 그 피라미드의 층(row)에 대한 값을 구해서 반환하는 문제입니다. 위의 이미지처럼 계속 되는 수들의 해당 층의 값을 구하면 됩니다. 1. Swift 1-1. 본인의 풀이 먼저 규칙성을 찾아봅시다. row : 1 = 1 row : 2 = 3 + 5 = 8 row : 3 = 7 + 9 + 11 = 27 ... 보면 row..

[Codewars] [8Kyu] Function 3 - multiplying two numbers

Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 이번 문제는 단순히 입력받은 두 값을 곱한 결과값을 리턴하는 문제입니다. 너무 단순해서 그냥 정리용으로 올립니다. func multiply(_ a: Double, _ b: Double) -> Double { // Write here your multiply-function return a * b }

[Codewars] [6Kyu] Counting Duplicates

Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 대소문자 구분 없이 숫자와 알파벳의 갯수가 2개 이상인 것들의 전체 갯수를 리턴하는 문제입니다. 1. Swift 1-1. 본인의 풀이 func countDuplicates(_ s:String) -> Int { let lower = s.lowercased() return Array(Set(lower)).filter{return lower.firstIndex(of: $0) ..

반응형