In my first attempt I realised that every third value is even.
So I just tried to hard code it at first by finding the even terms of the fibonacci sequence then adding them up.
This obviously isn't the most efficient and wouldn't give me the sum of the first 100 even terms quick enough!
So, I began researching on Maths Stack exchange, I did not want to cheat! I was looking for a theorem that I could code up and then I found this: Closed form for the sum of even fibonacci numbers? More, specifically:
This allowed me to quickly find the sum without any rigourous computation!!
Another issue that I encountered was that, finding the nth term for the Fibonacci sequence using the recursive function was not effeicient enough. So, I headed to maths Stack exchange again and found this: An nth term for a Fibonacci series? In particular:
I was now able to quickly work out the nth term of a Fibonacci sequence!
I defined two functions, one that calculated the nth term value for n < 10 and the other for the rest. This is due to the n > 6 condition placed on the theorem.
However, there was an issue. When it came to large numbers. JavaScript began to round them weirdly and I wasn't happy with the result.
Then, after some more brief research I decided to implement big.js which allowed me to manipulate large numbers more accurately.
I also decided to change my approach. Rather than going for a general solution to sum any amount of even Fibonacci sequence terms, I stuck to only finding the sum of the first 100.
However, I still wasn't able to get the full answer as it was 63 digits long:
With regards to question 2, I have not studies computer science properly except for one module at uni which wasn't extremely thorough. However, I am extremely keen on learning more and solidifying my fundementals God willing!
I really enjoyed this one. I made some assumptions which I hope are reasonable:
- The output array must be in Ascending order.
- That I did not have to remove duplicated and that the length of the output array must be the same as the sum of the 2 original arrays.
This was my faviourite one!
I had to do some research at first as to how to convert between the base 10 to another base (I started with 5).
I only checked the mathematical method and no code.
So, I followed the method through and coded it up, then when it came to adding the letters I realised that I just needed to swap the 10, 11, 12, 13's etc. with A, B, C, D's etc.
I was contemplating whether I should just go for a for loop with a huge list of if statements but I really really didn't want to do that.
Then by the blessings of God I realised I could use the ASCII conversions!
Sadly, this is the same as Q2 above.
I did not know this off the top off my head. I had to code it out and see what happens. I tried to give a reason for it but I'm not sure if its correct.
However, I'm also very keen on upping my skills in any language and mastering any fundementals needed God willing.
This question was fun, I had to check the syntax for the functions as I had forgotten how to do it from memory. Otherwise, it was pretty straight forward.