There are 3 ways to write 4 as a sum of odd numbers (assuming order matters and numbers can be repeated in the sum): 3+1, 1+3, and 1+1+1+1.
How many ways are there to write 19 as a sum of odd numbers?
Hint: The above result has something to do with Fibonacci numbers
DefDbl A-Z
Dim crlf$, ways, n, togo
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
For n = 2 To 25
ways = 0
togo = n
addon
Text1.Text = Text1.Text & n & Str(ways) & crlf
Next
Text1.Text = Text1.Text & ct & " done"
End Sub
Sub addon()
For amt = 1 To togo Step 2
togo = togo - amt
If togo = 0 Then
ways = ways + 1
Else
addon
End If
togo = togo + amt
Next
End Sub
finds
2 1
3 2
4 3
5 5
6 8
7 13
8 21
9 34
10 55
11 89
12 144
13 233
14 377
15 610
16 987
17 1597
18 2584
19 4181
20 6765
21 10946
22 17711
23 28657
24 46368
25 75025
For 19, the sum is 4181. I do see the Fibonacci sequence here.
|
Posted by Charlie
on 2019-05-09 14:13:14 |