Partition function P: Difference between revisions

Content added Content deleted
No edit summary
(Partition function P en FreeBASIC)
Line 347: Line 347:
193655306161707661080005073394486091998480950338405932486880600467114423441282418165863
193655306161707661080005073394486091998480950338405932486880600467114423441282418165863
</pre>
</pre>


=={{header|FreeBASIC}}==
{{trans|Python}}
<lang freebasic>
Function PartitionsP(n As Integer) As Single
Dim As Single p(n), k, j
p(0) = 1
For i As Integer = 1 To n + 1
k = 0
While True
k += 1
j = (k * (3*k - 1)) \ 2
If (j > i) Then Exit While
If (k And 1) Then
p(i) += p(i - j)
Else
p(i) -= p(i - j)
End If
j = (k * (3*k + 1)) \ 2
If (j > i) Then Exit While
If (k And 1) Then
p(i) += p(i - j)
Else
p(i) -= p(i - j)
End If
Wend
Next i
Return p(n)
End Function

Print !"\nPartitionsP: ";
For x As Integer = 0 To 12
print PartitionsP(x);" ";
Next x
Sleep
</lang>



=={{header|Go}}==
=={{header|Go}}==