Derive a formula for the number of partitions of n into parts that are odd and bigger than 1; e.g. a(12)=5 cases: 3+3+3+3, 5+7, 7+5, 3+9, 9+3.
Verify your formula by evaluating a(14).
What if the order didn't matter in the sums: for example, 5+7 and 7+5 counted as only one way of adding to 12?
DECLARE SUB decompose (x#, b#)
DEFDBL A-Z
CLEAR , , 25000
DIM SHARED ct
CLS
FOR n = 1 TO 45
ct = 0
decompose n, 3
PRINT n, ct
NEXT n
SUB decompose (x, b)
IF x < b THEN EXIT SUB
FOR addend = b TO x STEP 2
IF addend = x THEN
ct = ct + 1
ELSE
decompose x - addend, addend
END IF
NEXT
END SUB
1 0
2 0
3 1
4 0
5 1
6 1
7 1
8 1
9 2
10 2
11 2
12 3
13 3
14 4
15 5
16 5
17 6
18 8
19 8
20 10
21 12
22 13
23 15
24 18
25 20
26 23
27 27
28 30
29 34
30 40
31 44
32 50
33 58
34 64
35 73
36 83
37 92
38 104
39 118
40 131
41 147
42 166
43 184
44 206
45 232
|
Posted by Charlie
on 2013-01-24 15:04:11 |