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 #python8 years ago

Hi @isteemit

Here is my first attempt at this.
I have written this script in R

len <- 50
fibvals <- numeric(len)

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

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

}

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

As of now I have fixed the length of the Fib series to 50... but m trying to make it dynamic ... shall try in some time

Sort:  

The answer is 14328 as per my code

Hey @bsameep! Please do format the code, makes it easier to read. :D

You can check the previous submissions for reference.

Also, the limit is 400000, not 40000.

Hey sorry, but the code will work if u change 40000 to 400000... Here is the updated one...

len <- 100
fibvals <- numeric(len)

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

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

}

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

Right now m holidaying at Western coastal area... Won't get chance to run d code n reproduce the answer...

Umm okay, do try formatting it for readability though.

Loading...