Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

running gofix on all code

  • Loading branch information...
commit 890e3faf59cdf764896da82b43a70c073fbfbd30 1 parent ee06a3d
@fsouza fsouza authored
View
26 problem_011/11.go
@@ -14,7 +14,7 @@ func ConvertGridToString(grid *vector.Vector) string {
line := lineInterface.(*vector.IntVector)
for j, number := range *line {
format = "%d"
- if j + 1 != line.Len() {
+ if j+1 != line.Len() {
format += " "
}
@@ -31,12 +31,12 @@ func ConvertGridToString(grid *vector.Vector) string {
func ReadGridFromString(input string) *vector.Vector {
grid := new(vector.Vector)
- lines := strings.Split(input, "\n", -1)
+ lines := strings.Split(input, "\n")
for _, line := range lines {
lineVector := new(vector.IntVector)
- numbers := strings.Split(line, " ", -1)
+ numbers := strings.Split(line, " ")
for _, number := range numbers {
number, _ := strconv.Atoi(number)
lineVector.Push(number)
@@ -55,9 +55,9 @@ func GridProduct(grid *vector.Vector, elements int) uint {
for _, lineInterface := range *grid {
line := lineInterface.(*vector.IntVector)
lineLength = line.Len()
- for i := 0; i < line.Len() - elements + 1; i++ {
+ for i := 0; i < line.Len()-elements+1; i++ {
product = 1
- for j := i; j < i + elements; j++ {
+ for j := i; j < i+elements; j++ {
product *= uint(line.At(j))
}
@@ -68,9 +68,9 @@ func GridProduct(grid *vector.Vector, elements int) uint {
}
for i := 0; i < lineLength; i++ {
- for j := 0; j < grid.Len() - elements + 1; j++ {
+ for j := 0; j < grid.Len()-elements+1; j++ {
product = 1
- for k := j; k < j + elements; k++ {
+ for k := j; k < j+elements; k++ {
line := grid.At(k).(*vector.IntVector)
product *= uint(line.At(i))
}
@@ -81,12 +81,12 @@ func GridProduct(grid *vector.Vector, elements int) uint {
}
}
- for i := 0; i < grid.Len() - elements + 1; i++ {
+ for i := 0; i < grid.Len()-elements+1; i++ {
line := grid.At(i).(*vector.IntVector)
- for j := 0; j < line.Len() - elements + 1; j++ {
+ for j := 0; j < line.Len()-elements+1; j++ {
l := j
product = 1
- for k := i; k < i + 4; k++ {
+ for k := i; k < i+4; k++ {
product *= uint(grid.At(k).(*vector.IntVector).At(l))
l++
}
@@ -97,12 +97,12 @@ func GridProduct(grid *vector.Vector, elements int) uint {
}
}
- for i := grid.Len() - 1; i >= elements - 1; i-- {
+ for i := grid.Len() - 1; i >= elements-1; i-- {
line := grid.At(i).(*vector.IntVector)
- for j := 0; j < line.Len() - elements + 1; j++ {
+ for j := 0; j < line.Len()-elements+1; j++ {
l := j
product = 1
- for k := i; k > i - 4; k-- {
+ for k := i; k > i-4; k-- {
product *= uint(grid.At(k).(*vector.IntVector).At(l))
l++
}
View
14 problem_012/12.go
@@ -12,18 +12,18 @@ func GetPrimeFactors(number int) (*vector.IntVector, *vector.IntVector) {
primesChannel := GetPrimes()
result := number
- for {
+ for {
prime := <-primesChannel
if number < prime {
break
}
- if result % prime == 0 {
+ if result%prime == 0 {
numbers.Push(prime)
count := 1
- for result = result / prime; result % prime == 0; result = result / prime {
+ for result = result / prime; result%prime == 0; result = result / prime {
count++
}
@@ -45,22 +45,22 @@ func CountDivisors(number int) int {
return count
}
-func FindTriangleNumberAt(index int, cache map[int] int) int {
+func FindTriangleNumberAt(index int, cache map[int]int) int {
_, foundOnCache := cache[index]
if !foundOnCache {
if index == 1 {
return index
}
- cache[index] = index + FindTriangleNumberAt(index - 1, cache)
- cache[index - 1] = 0, false
+ cache[index] = index + FindTriangleNumberAt(index-1, cache)
+ delete(cache, index-1)
}
return cache[index]
}
func FindFirstNumberToOverLimit(limit int) int {
- triangleCache := make(map[int] int)
+ triangleCache := make(map[int]int)
minimum := int(math.Pow(float64(limit), 2))
for i := 1; ; i++ {
View
4 problem_013/13.go
@@ -6,7 +6,7 @@ import (
)
func SumDigitsOf(number uint) uint {
- digits := strconv.Uitoa(number)
+ digits := strconv.FormatUint(uint64(number), 10)
sum := uint(0)
for _, digit := range digits {
sum += uint(digit - '0')
@@ -16,7 +16,7 @@ func SumDigitsOf(number uint) uint {
}
func SliceDigits(number, length uint) string {
- digits := strconv.Uitoa(number)
+ digits := strconv.FormatUint(uint64(number), 10)
return digits[:length]
}
View
4 problem_016/16.go
@@ -8,7 +8,7 @@ import (
func SumDigits(number uint64) uint64 {
var sum uint64
- digits := strconv.Uitoa64(number)
+ digits := strconv.FormatUint(number, 10)
for _, digit := range digits {
sum += uint64(digit - '0')
}
@@ -19,7 +19,7 @@ func SumDigits(number uint64) uint64 {
func Pow(base, exponent uint64) uint64 {
product := base
- for i := uint64(0); i < exponent - 1; i++ {
+ for i := uint64(0); i < exponent-1; i++ {
product *= base
}
View
2  problem_020/20.go
@@ -1,8 +1,8 @@
package main
import (
- "big"
"fmt"
+ "math/big"
)
func SumDigitsOf(number *big.Int) int {
View
4 problem_020/20_test.go
@@ -1,12 +1,12 @@
package main
import (
- "big"
+ "math/big"
"testing"
)
type FactorialTest struct {
- in int64
+ in int64
out *big.Int
}
View
6 problem_025/25.go
@@ -1,8 +1,8 @@
package main
import (
- "big"
"fmt"
+ "math/big"
)
func Fibonacci(number int64) *big.Int {
@@ -17,6 +17,8 @@ func Fibonacci(number int64) *big.Int {
func main() {
number := int64(0)
- for len(Fibonacci(number).String()) < 1000 { number++ }
+ for len(Fibonacci(number).String()) < 1000 {
+ number++
+ }
fmt.Println(number)
}
View
10 problem_025/25_test.go
@@ -1,19 +1,19 @@
package main
import (
- "big"
+ "math/big"
"testing"
)
type FibonacciTest struct {
- in int64
+ in int64
out *big.Int
}
var FibonacciTests = []FibonacciTest{
- FibonacciTest{ 3, big.NewInt(2) },
- FibonacciTest{ 7, big.NewInt(13) },
- FibonacciTest{ 9, big.NewInt(34) },
+ FibonacciTest{3, big.NewInt(2)},
+ FibonacciTest{7, big.NewInt(13)},
+ FibonacciTest{9, big.NewInt(34)},
}
func TestFibonacci(t *testing.T) {
View
2  problem_029/29.go
@@ -1,8 +1,8 @@
package main
import (
- "big"
"fmt"
+ "math/big"
)
func IsPresent(sequence []*big.Int, number *big.Int) bool {
View
4 problem_029/29_test.go
@@ -1,7 +1,7 @@
package main
import (
- "big"
+ "math/big"
"testing"
)
@@ -14,7 +14,6 @@ func TestIsPresent(t *testing.T) {
}
}
-
func TestAddToSequence(t *testing.T) {
sequence := make([]*big.Int, 0)
sequence = AddToSequence(sequence, big.NewInt(0), big.NewInt(1))
@@ -25,7 +24,6 @@ func TestAddToSequence(t *testing.T) {
}
}
-
func TestFindTermsCountInSequence(t *testing.T) {
expected := 15
got := CountTermsInSequence(5, 5)
View
6 problem_034/34.go
@@ -1,8 +1,8 @@
package main
import (
- "big"
"fmt"
+ "math/big"
"strconv"
)
@@ -26,8 +26,8 @@ func main() {
sum := int64(0)
for i := int64(10); i < 50000; i++ {
factorialSum := int64(0)
- for _, digit := range strconv.Itoa64(i) {
- factorialSum += factorials[digit - '0'].Int64()
+ for _, digit := range strconv.FormatInt(i, 10) {
+ factorialSum += factorials[digit-'0'].Int64()
}
if factorialSum == i {
Please sign in to comment.
Something went wrong with that request. Please try again.