Taxicab numbers: Difference between revisions
Content deleted Content added
Kinitawowi (talk | contribs) |
m →{{header|Go}}: User new and more efficient strings.Builder, remove timings |
||
Line 1,026: | Line 1,026: | ||
"container/heap" |
"container/heap" |
||
"fmt" |
"fmt" |
||
"strings" |
|||
) |
) |
||
Line 1,083: | Line 1,084: | ||
func (t Taxicab) String() string { |
func (t Taxicab) String() string { |
||
var b strings.Builder |
|||
//return fmt.Sprintf("%12d =%5d³ +%5d³ =%5d³ +%5d³", |
|||
fmt.Fprintf(&b, "%12d", t[0].value) |
|||
// Likely more efficient to use a bytes.Buffer here. |
|||
s := fmt.Sprintf("%12d", t[0].value) |
|||
for _, p := range t { |
for _, p := range t { |
||
fmt.Fprintf(&b, " =%5d³ +%5d³", p.x, p.y) |
|||
} |
} |
||
return |
return b.String() |
||
} |
} |
||
Line 1,123: | Line 1,121: | ||
) |
) |
||
var tg TaxicabGen |
var tg TaxicabGen |
||
firstn := 3 // To show the first |
firstn := 3 // To show the first triple, quadruple, etc |
||
for i := 1; i <= high+6; i++ { |
for i := 1; i <= high+6; i++ { |
||
t := tg.Next() |
t := tg.Next() |
||
Line 1,136: | Line 1,134: | ||
} |
} |
||
}</lang> |
}</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}} |
{{out}} |
||
<pre> |
<pre> |