var nums = "3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99".split(", ");
for(var i = 0;i< nums.length;i++) { nums[i] = parseInt(nums[i],10); }
Instead of just editing the numbers so that it was an array right away. Happens if you code before you think :-)
Maybe you should have called it the "Greplin Challenge," then, instead of the "Greplin Programming Challenge." It's not a real task, after all; the reward comes from accepting a completely artificial challenge. I'm going to do the challenge before dinner tonight, and before I leave work I could get source code for the solutions from the guy down the hall from me who did the challenge as soon as it was posted -- and you certainly don't want to hire a guy who recodes other people's work for no reason, right?
int((1/math.sqrt(5))*(math.pow(((1+math.sqrt(5))/2),fibonacci)-math.pow(((1-math.sqrt(5))/2),fibonacci)))
Reference here: http://mathproofs.blogspot.com/2005/04/nth-term-of-fibonacci...
n
[0 1] = [fib(n) fib(n+1)]
[1 1] [fib(n+1) fib(n+2)]
With repeated squarings, you can efficiently generate any Fibonacci number you want. # memoized fibonacci function
fibtable = {1:1, 0:1}
def fib (n):
global fibtable
if n in fibtable.keys():
return fibtable [n]
val = fib (n-1) + fib (n-2)
fibtable [n] = val
return val last_fib = 0
fib = 1
while fib < 225000 or not is_prime(fib):
last_fib, fib = fib, last_fib + fibIt was way more fun to do it from scratch :D
Thanks grepplin
p.s. the csv was copied in my [] python list :)
I would be curious how many people did you lose because of phonecall requirement (before you changed it).
Also CSV for just a list of 22 numbers wasn't really necessary.
If you do web puzzle, the best is to keep everything self-contained, no downloads, no using external channels, just copy and paste.
FYI another Python cheater here (+Wolfram Alpha & Wikipedia, I'm lazy :).