42: update test

This commit is contained in:
VicRen
2020-11-25 15:17:34 +08:00
parent 39a6ae56df
commit 33e5d4b47e
2 changed files with 14 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"fmt"
"io/ioutil"
"math"
"strings"
)
@@ -40,7 +41,7 @@ func worthOf(word string) int {
sum := 0
for i := 0; i < len(word); i++ {
a := word[i : i+1][0]
w := uint8(a) - BASE
w := a - 'A' + 1
sum += int(w)
}
return sum
@@ -49,12 +50,8 @@ func worthOf(word string) int {
func isTriangleNumber(n int) bool {
//tn = ½n(n+1)
x := 2 * n
res := x
//牛顿法求平方根
for res*res > x {
res = (res + x/res) / 2
}
for i := res; i > 0; i-- {
r := int(math.Sqrt(float64(x)))
for i := r; i > 0; i-- {
if i*(i+1) == x {
return true
}

View File

@@ -86,6 +86,16 @@ func Test_isTriangleNumber(t *testing.T) {
args{29},
false,
},
{
"55",
args{55},
true,
},
{
"56",
args{56},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {