Perfect numbers: Difference between revisions

Content added Content deleted
(make the math prominent)
Line 748: Line 748:
=={{header|Go}}==
=={{header|Go}}==


{{incorrect|Go|The point is to demonstrate finding perfect numbers in each language, not to return True on certain inputs, which is what we call optimising for the given test cases. All the other answers actually calculate things; why you gotta make Go look bad?}}
<lang go>package main
<lang go>package main


import "fmt"
import "fmt"

func computePerfect(n int64) bool {
var sum int64
for i := int64(1); i < n; i++ {
if n%i == 0 {
sum += i
}
}
return sum == n
}


// following function satisfies the task, returning true for all
// following function satisfies the task, returning true for all
Line 776: Line 785:
}
}


</lang>
func computePerfect(n int64) bool {
var sum int64
for i := int64(1); i < n; i++ {
if n%i == 0 {
sum += i
}
}
return sum == n
}</lang>
{{Out}}
{{Out}}
<pre>
<pre>