Skip to content

Commit 0e119e0

Browse files
committed
Fixed lint
1 parent 872e476 commit 0e119e0

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

golang/6_kyu_sum_of_digits.go

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
1-
package main
2-
3-
import (
4-
"fmt"
5-
)
6-
7-
func sumDigits(number int) int {
8-
remainder := 0
9-
sumResult := 0
10-
for number != 0 {
11-
remainder = number % 10
12-
sumResult += remainder
13-
number = number / 10
14-
}
15-
return sumResult
16-
}
1+
/*
2+
3+
Digital root is the recursive sum of all the digits in a number.
4+
5+
Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers.
6+
7+
Examples
8+
16 --> 1 + 6 = 7
9+
942 --> 9 + 4 + 2 = 15 --> 1 + 5 = 6
10+
132189 --> 1 + 3 + 2 + 1 + 8 + 9 = 24 --> 2 + 4 = 6
11+
493193 --> 4 + 9 + 3 + 1 + 9 + 3 = 29 --> 2 + 9 = 11 --> 1 + 1 = 2
12+
13+
*/
14+
15+
package kata
1716

18-
func main() {
19-
n := 195
17+
func DigitalRoot(n int) int {
2018
var result int
2119

2220
for {
23-
n = sumDigits(n)
21+
n = sumDigits(n)
22+
23+
if n < 10 {
24+
result = n
25+
break
26+
}
27+
}
28+
29+
return result
30+
}
31+
32+
func sumDigits(number int) int {
33+
remainder := 0
34+
sumResult := 0
2435

25-
if n < 10 {
26-
result = n
27-
break
28-
}
36+
for number != 0 {
37+
remainder = number % 10
38+
sumResult += remainder
39+
number = number / 10
2940
}
3041

31-
fmt.Println(result)
42+
return sumResult
3243
}

0 commit comments

Comments
 (0)