반응형

풀이 4

[Codewars] [5kyu] Product of consecutive Fib 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 피보나치 수열의 값들을 이용해서 Input된 값과 비교해서 결과를 반환하는 문제입니다. 1. Swift 1-1. 본인의 풀이 입력된 값은 피보나치 숫자의 앞 뒤 값(F(n), F(n+1))을 곱한 값과의 일치여부를 계산해서 반환하는 문제입니다. 피보나치 수는 아시겠지만, 0과 1로 시작해서 다음 숫자는 그 바로 앞 두 숫자의 합이 되..

[Codewars] [6kyu] Duplicate Encoder

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개 이상이 나오는 character는 ")"로, 그 외는 "("로 치환하는 문제입니다. 1. Swift 1-1. 본인의 풀이 입력된 단어를 일단 소문자로 모두 바꾸고, 각 character의 첫번째 인덱스 값과 마지막 인덱스 값이 동일한지 여부를 판단해서 인덱스가 동일하면 한 개만 존재하는 character, 그 외는 2개 이상이 존재하는 character라고 판단하고..

[Codewars] [8kyu] Dollars and Cents

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 Double형 값이 입력되면 $를 붙여서 String으로 반환하는 문제입니다. 1. Swift 1-1. 본인의 풀이 String(format: String, CVarArg...)을 이용합니다. 소숫점 둘째자리까지 출력을 하기 때문에 %.2f를 사용하고, 그 앞에 $를 붙입니다. import Foundation func formatMoney(_ val:Double) -> ..

[Codewars] [8kyu] To square(root) or not to square(root)

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 루트로 나눠지는 값들은 제곱근, 그 외는 제곱을 해서 배열로 반환하는 문제입니다. 1. Swift 1-1. 본인의 풀이 저의 경우 input의 각 element의 제곱근을 구한 값을 Int로 변환 후 그 값들을 다시 제곱 한 값이 원래 값(element)과 같으면 제곱근, 아니라면 element 값을 제곱한 값을 반환할 배열(returnArr)에 각각 저장하면 된다고 생..

반응형