Groovy web console

subscribe to the feed Subscribe
to this
site

valery task 2

Published 2 months ago by auk
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
int fib_prev = 0, fib = 1

int sum = 0
while (fib < 4000000) {
  (fib_prev, fib) = [fib, fib + fib_prev]
  println "Fib: ${fib}"
  if (fib % 2 == 0)
    sum += fib
}

println "Sum: ${sum}"