Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- KX Community
- :
- Discussion Forums
- :
- kdb+ and q
- :
- Re: Q For Problems - Episode 2

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Q For Problems - Episode 2

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2022.10.04 03:47 AM - last edited on 2022.10.04 04:51 AM by DBaker

Hi everyone,

Please check out episode 2 of the Q For Problems video series.

This covers problem 2 from the Project Euler problem set. Project Euler - Problem 2

Feel free to share your own solutions and ideas in the comments.

Thanks

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2022.10.04 11:36 AM

Brilliant video @jkane71👏

Thank you for creating this series and sharing with us!

Looking forward to the next episode,

*Leah*

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2022.10.05 07:23 AM

Sweet! And you can skip the arithmetic – every third Fibonacci number is even:

```
q)fib:{x,sum -2#x}/[;0 1]
q)fibm:{-1 _ fib(x>last@)}
q)fibm 4000000
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17..
q)sum{x where count[x]#100b}fibm 4000000
4613732
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2022.10.05 07:39 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2022.10.05 07:08 PM

It's also possible to calculate the n-th Fibonacci number directly using the golden ratio, phi. So for this case, we can just calculate every 3rd number since we know they are even.

```
q)phi:0.5*1+sqrt 5
q)fibn:{reciprocal[sqrt 5]*(-/)xexp[;y]x,1-x}[phi;]
q)sum -1_{4000000>last x}{x,fibn 3*count x}/0f
4613732f
```

Main Office Contacts

**EMEA**

Tel: +44 (0)28 3025 2242

**AMERICAS**

Tel: +1 (212) 447 6700

**APAC**

Tel: +61 (0)2 9236 5700

Useful Information

Resources

Popular Links

Follow Us

KX. All Rights Reserved.

KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.