Jump to content

Taxicab numbers: Difference between revisions

m
→‎{{header|Go}}: User new and more efficient strings.Builder, remove timings
m (→‎{{header|Go}}: User new and more efficient strings.Builder, remove timings)
Line 1,026:
"container/heap"
"fmt"
"strings"
)
 
Line 1,083 ⟶ 1,084:
 
func (t Taxicab) String() string {
var b strings.Builder
//return fmt.Sprintf("%12d =%5d³ +%5d³ =%5d³ +%5d³",
// t[0]fmt.valueFprintf(&b, t[0].x"%12d", t[0].y, t[1].x, t[1].yvalue)
 
// Likely more efficient to use a bytes.Buffer here.
s := fmt.Sprintf("%12d", t[0].value)
for _, p := range t {
s = s + fmt.SprintfFprintf(&b, " =%5d³ +%5d³", p.x, p.y)
}
return sb.String()
}
 
Line 1,123 ⟶ 1,121:
)
var tg TaxicabGen
firstn := 3 // To show the first trippletriple, quadruple, etc
for i := 1; i <= high+6; i++ {
t := tg.Next()
Line 1,136 ⟶ 1,134:
}
}</lang>
On a modern 64 bit processor this takes ~89 msec for the first 2000 and ~9.2 sec for the first 40,000.
{{out}}
<pre>
1,707

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.