Skip to content

Instantly share code, notes, and snippets.

@stripe-q
Created December 21, 2018 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stripe-q/80aefab0e47deb918c54f81bbc6c6e9d to your computer and use it in GitHub Desktop.
Save stripe-q/80aefab0e47deb918c54f81bbc6c6e9d to your computer and use it in GitHub Desktop.
# 코루틴을 이용해서 피보나치 수열을 만들기
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