๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

swift230

[Swift] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค LV.0 ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ(2) ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค LV.0 ๋ชจ์Œ ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ ๋ฌธ์ œ ์„ค๋ช… ๋จธ์“ฑ์ด๋„ค ํ”ผ์ž๊ฐ€๊ฒŒ๋Š” ํ”ผ์ž๋ฅผ ์—ฌ์„ฏ ์กฐ๊ฐ์œผ๋กœ ์ž˜๋ผ ์ค๋‹ˆ๋‹ค. ํ”ผ์ž๋ฅผ ๋‚˜๋ˆ ๋จน์„ ์‚ฌ๋žŒ์˜ ์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, n๋ช…์ด ์ฃผ๋ฌธํ•œ ํ”ผ์ž๋ฅผ ๋‚จ๊ธฐ์ง€ ์•Š๊ณ  ๋ชจ๋‘ ๊ฐ™์€ ์ˆ˜์˜ ํ”ผ์ž ์กฐ๊ฐ์„ ๋จน์–ด์•ผ ํ•œ๋‹ค๋ฉด ์ตœ์†Œ ๋ช‡ ํŒ์„ ์‹œ์ผœ์•ผ ํ•˜๋Š”์ง€๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. ์ œํ•œ ์‚ฌํ•ญ 1 ≤ n ≤ 100 ์ž…์ถœ๋ ฅ ์˜ˆ n result 6 1 10 5 4 2 ์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช… ์ž…์ถœ๋ ฅ ์˜ˆ #1 6๋ช…์ด ๋ชจ๋‘ ๊ฐ™์€ ์–‘์„ ๋จน๊ธฐ ์œ„ํ•ด ํ•œ ํŒ์„ ์‹œ์ผœ์•ผ ํ”ผ์ž๊ฐ€ 6์กฐ๊ฐ์œผ๋กœ ๋ชจ๋‘ ํ•œ ์กฐ๊ฐ์”ฉ ๋จน์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 10๋ช…์ด ๋ชจ๋‘ ๊ฐ™์€ ์–‘์„ ๋จน๊ธฐ ์œ„ํ•ด ์ตœ์†Œ 5ํŒ์„ ์‹œ์ผœ์•ผ ํ”ผ์ž๊ฐ€ 30์กฐ๊ฐ์œผ๋กœ ๋ชจ๋‘ ์„ธ ์กฐ๊ฐ์”ฉ ๋จน์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #3 4๋ช…์ด ๋ชจ๋‘ ๊ฐ™์€ ์–‘์„.. 2022. 11. 30.
[Swift] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค LV.0 ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ (1) ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค LV.0 ๋ชจ์Œ ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ ๋ฌธ์ œ ์„ค๋ช… ๋จธ์“ฑ์ด๋„ค ํ”ผ์ž๊ฐ€๊ฒŒ๋Š” ํ”ผ์ž๋ฅผ ์ผ๊ณฑ ์กฐ๊ฐ์œผ๋กœ ์ž˜๋ผ ์ค๋‹ˆ๋‹ค. ํ”ผ์ž๋ฅผ ๋‚˜๋ˆ ๋จน์„ ์‚ฌ๋žŒ์˜ ์ˆ˜ n์ด ์ฃผ์–ด์งˆ ๋•Œ, ๋ชจ๋“  ์‚ฌ๋žŒ์ด ํ”ผ์ž๋ฅผ ํ•œ ์กฐ๊ฐ ์ด์ƒ ๋จน๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ํ”ผ์ž์˜ ์ˆ˜๋ฅผ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. ์ œํ•œ ์‚ฌํ•ญ 1 ≤ n ≤ 100 ์ž…์ถœ๋ ฅ ์˜ˆ n result 7 1 1 1 15 3 ์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช… ์ž…์ถœ๋ ฅ ์˜ˆ #1 7๋ช…์ด ์ตœ์†Œ ํ•œ ์กฐ๊ฐ์”ฉ ๋จน๊ธฐ ์œ„ํ•ด์„œ ์ตœ์†Œ 1ํŒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 1๋ช…์€ ์ตœ์†Œ ํ•œ ์กฐ๊ฐ์„ ๋จน๊ธฐ ์œ„ํ•ด 1ํŒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #3 15๋ช…์ด ์ตœ์†Œ ํ•œ ์กฐ๊ฐ์”ฉ ๋จน๊ธฐ ์œ„ํ•ด์„œ ์ตœ์†Œ 3ํŒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ œ์ถœ import Foundation func solution(_ n:Int) -> Int { return n/7 .. 2022. 11. 30.
[Swift] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค LV.0 ์ง์ˆ˜๋Š” ์‹ซ์–ด์š” ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค LV.0 ๋ชจ์Œ ์ง์ˆ˜๋Š” ์‹ซ์–ด์š” ๋ฌธ์ œ ์„ค๋ช… ์ •์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, n ์ดํ•˜์˜ ํ™€์ˆ˜๊ฐ€ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ๋‹ด๊ธด ๋ฐฐ์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ ์‚ฌํ•ญ 1 ≤ n ≤ 100 ์ž…์ถœ๋ ฅ ์˜ˆ n result 10 [1, 3, 5, 7, 9] 15 [1, 3, 5, 7, 9, 11, 13, 15] ์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช… ์ž…์ถœ๋ ฅ ์˜ˆ #1 10 ์ดํ•˜์˜ ํ™€์ˆ˜๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด [1, 3, 5, 7, 9]๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 15 ์ดํ•˜์˜ ํ™€์ˆ˜๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด [1, 3, 5, 7, 9, 11, 13, 15]๋ฅผ return ํ•ฉ๋‹ˆ๋‹ค. ์ œ์ถœ import Foundation func solution(_ n:Int) -> [Int] { var answer = [Int]() for i.. 2022. 11. 30.
[Swift] Codility Lesson 5 - CountDiv ๋ฌธ์ œ Write a function: public func solution(_ A : Int, _ B : Int, _ K : Int) -> Int that, given three integers A, B and K, returns the number of integers within the range [A..B] that are divisible by K, i.e.: { i : A ≤ i ≤ B, i mod K = 0 } For example, for A = 6, B = 11 and K = 2, your function should return 3, because there are three numbers divisible by 2 within the range [6..11], namely 6, 8 an.. 2022. 7. 26.
[Swift] Codility Lesson 5 - PassingCars ๋ฌธ์ œ A non-empty array A consisting of N integers is given. The consecutive elements of array A represent consecutive cars on a road. Array A contains only 0s and/or 1s: 0 represents a car traveling east, 1 represents a car traveling west. The goal is to count passing cars. We say that a pair of cars (P, Q), where 0 ≤ P < Q < N, is passing when P is traveling to the east and Q is traveling to the .. 2022. 7. 26.
[Swift] Codility Lesson 4 - MissingInteger ๋ฌธ์ œ This is a demo task. Write a function: public func solution(_ A : inout [Int]) -> Int that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5. Given A = [1, 2, 3], the function should return 4. Given A = [−1, −3], the function should return 1. Write an efficie.. 2022. 7. 24.
๋ฐ˜์‘ํ˜•