프로그래머스/Lv.1
[Swift] 기사단원의 무기
물복딱복준복
2023. 2. 12. 00:08
import Foundation
func solution(_ number:Int, _ limit:Int, _ power:Int) -> Int {
var attack = [Int](repeating: 0, count: number+1)
for i in 1...number {
var c = i
while c <= number {
attack[c] += 1
c += i
}
print(attack)
}
attack = attack.map { $0 > limit ? power : $0 }
return attack.reduce(0, +)
}