편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.
최신판 | 당신의 편집 | ||
1번째 줄: | 1번째 줄: | ||
==Kotlin== | ==Kotlin== | ||
{{카타|7급|Kotlin|1}} | {{카타|7급|Kotlin|1}} | ||
< | <source lang='kotlin'> | ||
package growth | package growth | ||
fun nbYear(pp0:Int, percent:Double, aug:Int, p:Int):Int { | fun nbYear(pp0:Int, percent:Double, aug:Int, p:Int):Int { | ||
31번째 줄: | 12번째 줄: | ||
return(year) | return(year) | ||
} | } | ||
</ | </source> | ||
< | <source lang='kotlin'> | ||
package growth | package growth | ||
fun nbYear(pp0:Int, percent:Double, aug:Int, p:Int):Int = generateSequence(pp0) { it + (applyPercent(percent, it)) + aug }.indexOfFirst { it >= p } | fun nbYear(pp0:Int, percent:Double, aug:Int, p:Int):Int = generateSequence(pp0) { it + (applyPercent(percent, it)) + aug }.indexOfFirst { it >= p } | ||
val applyPercent: (Double, Int) -> Int = { a, b -> (a/100*b).toInt()} | val applyPercent: (Double, Int) -> Int = { a, b -> (a/100*b).toInt()} | ||
</ | </source> | ||
< | <source lang='kotlin'> | ||
package growth | package growth | ||
fun nbYear(pp0: Int, percent: Double, aug: Int, p: Int): Int = | fun nbYear(pp0: Int, percent: Double, aug: Int, p: Int): Int = | ||
generateSequence(pp0.toDouble()) { it * (1 + percent / 100) + aug }.takeWhile { it < p }.count() | generateSequence(pp0.toDouble()) { it * (1 + percent / 100) + aug }.takeWhile { it < p }.count() | ||
</ | </source> | ||
< | <source lang='kotlin'> | ||
package growth | package growth | ||
fun nbYear(p0: Int, percent: Double, aug: Int, p: Int): Int { | fun nbYear(p0: Int, percent: Double, aug: Int, p: Int): Int { | ||
50번째 줄: | 31번째 줄: | ||
return iter(0, p0) | return iter(0, p0) | ||
} | } | ||
</ | </source> | ||
==R== | ==R== | ||
{{카타|7급|R|2}} | {{카타|7급|R|2}} | ||
< | <source lang='r'> | ||
nbYear <- function (p0, percent, aug, p) { | nbYear <- function (p0, percent, aug, p) { | ||
year = 0 | year = 0 | ||
63번째 줄: | 44번째 줄: | ||
return(year) | return(year) | ||
} | } | ||
</ | </source> |