You are viewing a single comment's thread from:

RE: 01. LPTHW (A Good First Program - ex1.py) || Announcement of the winners of the last challenge. || New challenges at the end.

in #python7 years ago (edited)

#Assign 100 as the length of the fibonacci series with an assumption that 400000 will fall within this length
#fibvals is the fibonaci series with length 100
len <- 100
fibvals <- numeric(len)

#assign values 1,1 to the first two elements of Fiboonacci series

fibvals[1] <- 1
fibvals[2] <- 1

#from 3rd element to 100th element generate Fibonacci series till it is less than 400,000

for (i in 3:len)
{
if(fibvals[i-1]+fibvals[i-2] > 400000)
{
break
}
else

fibvals[i] <- fibvals[i-1]+fibvals[i-2]

}

#Sum of all the even numbers in the series (division of the series element with 2 should be 0)

sum(fibvals[fibvals %% 2 ==0])

#Result

if first two values in the Fibnocci series are as 1 and 1 then 257114 (as the script above)

if first two values in the Fibnocci series are as 1 and 2 then 257113

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63818.94
ETH 2624.28
USDT 1.00
SBD 2.78