-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathp76.bas
More file actions
41 lines (34 loc) · 751 Bytes
/
p76.bas
File metadata and controls
41 lines (34 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
REM Sum terms in recurrence relation for partition function
DECLARE FUNCTION sum& (n%)
total% = 100
DIM SHARED lookup&(total% + 1)
lookup&(0) = 1
FOR i% = 1 TO total%
plusone& = sum&(i%)
NEXT
REM Minus one because the problem specifies "at least two positive integers"
PRINT (plusone& - 1)
FUNCTION sum& (n%)
REM t& is the total, f% is the sign, good% indicates we should continue
t& = 0
f% = 1
good% = 1
k% = 1
WHILE good% = 1
good% = 0
i% = n% - (k% * ((3 * k%) - 1) / 2)
IF i% >= 0 THEN
good% = 1
t& = t& + (f% * lookup&(i%))
END IF
i% = n% - (k% * ((3 * k%) + 1) / 2)
IF i% >= 0 THEN
good% = 1
t& = t& + (f% * lookup&(i%))
END IF
k% = k% + 1
f% = (-1) * f%
WEND
lookup&(n%) = t&
sum& = t&
END FUNCTION