Created
December 21, 2018 02:48
-
-
Save stripe-q/80aefab0e47deb918c54f81bbc6c6e9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 코루틴을 이용해서 피보나치 수열을 만들기 | |
begin | |
# 코루틴을 생성한다. | |
# f = (chnl) -> ... 이고 | |
# c = Channel(f) 인데 | |
# 이것을 하나의 구문으로 합친다. | |
# fib는 사실상 Channel이다. | |
fib = Channel() do c | |
a, b = 0, 1 | |
while true | |
put!(c, a) | |
a, b = b, a+b | |
end | |
end | |
let (s, n) = (0, 0) | |
while true | |
n = take!(fib) | |
n > 4000000 && break | |
s += n % 2 == 0 ? n : 0 | |
end | |
println(s) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment