Man or boy test: Difference between revisions

→‎{{header|Go}}: Don't think Sonia ever intended the 'faster' version to work for k < 6 but I've modified it now so it does.
(→‎{{header|Phix}}: added gmp version)
(→‎{{header|Go}}: Don't think Sonia ever intended the 'faster' version to work for k < 6 but I've modified it now so it does.)
Line 1,758:
 
Inspired by D's "faster" version, here's another that uses a different algorithm to compute the result.
{{incorrect|Go|wrong results for A(0)..A(5), see Phix entry}}
<lang go>package main
 
Line 1,767 ⟶ 1,766:
 
func A(k int) *big.Int {
if k < 6 {
var x1, x2, x3, x4 int64 = 1, -1, -1, 1
c1 := []int64{0, 0, 0, 1, 2, 3}[k]
c2 := []int64{0, 0, 1, 1, 1, 2}[k]
c3 := []int64{0, 1, 1, 0, 0, 1}[k]
c4 := []int64{1, 1, 0, 0, 0, 0}[k]
t := c1*x1 + c2*x2 + c3*x3 + c4*x4
return big.NewInt(t)
p(10)}
one := big.NewInt(1)
c0 := big.NewInt(3)
Line 1,792 ⟶ 1,800:
 
func main() {
for i := 0; i < 40; i++ {
p(10)
p(30i)
}
p(500)
p(10000)
Line 1,800 ⟶ 1,809:
{{out}}
<pre>
A(0) = 1
A(1) = 0
A(2) = -2
A(3) = 0
A(4) = 1
A(5) = 0
A(6) = 1
A(7) = -1
A(8) = -10
A(9) = -30
A(10) = -67
A(11) = -138
A(12) = -291
A(13) = -642
A(14) = -1446
A(15) = -3250
A(16) = -7244
A(17) = -16065
A(18) = -35601
A(19) = -78985
A(20) = -175416
A(21) = -389695
A(22) = -865609
A(23) = -1922362
A(24) = -4268854
A(25) = -9479595
A(26) = -21051458
A(27) = -46750171
A(28) = -103821058
A(29) = -230560902
A(30) = -512016658
A(31) = -1137056340
A(32) = -2525108865
A(33) = -5607619809
A(34) = -12453091089
A(35) = -27655133488
A(36) = -61414977599
A(37) = -136386945105
A(38) = -302880491178
A(39) = -672620048590
A(500) = -36608...67320 (172 digits)
A(10000) = -19928...34899 (3464 digits)
9,476

edits