diff --git a/exercises/hackerrank/warmup/aVeryBigSum.go b/exercises/hackerrank/warmup/aVeryBigSum.go index be840dc..affa786 100644 --- a/exercises/hackerrank/warmup/aVeryBigSum.go +++ b/exercises/hackerrank/warmup/aVeryBigSum.go @@ -4,9 +4,7 @@ package hackerrank -import ( - utils "gon.cl/algorithms/utils" -) +import "gon.cl/algorithms/utils/log" func AVeryBigSum(ar []uint64) uint64 { var result uint64 = 0 @@ -15,6 +13,6 @@ func AVeryBigSum(ar []uint64) uint64 { result += ar[i] } - utils.Info("aVeryBigSum answer => %d", result) + log.Info("aVeryBigSum answer => %d", result) return result } diff --git a/exercises/hackerrank/warmup/compareTriplets.go b/exercises/hackerrank/warmup/compareTriplets.go index f6b1d93..7d0ebb4 100644 --- a/exercises/hackerrank/warmup/compareTriplets.go +++ b/exercises/hackerrank/warmup/compareTriplets.go @@ -7,7 +7,7 @@ package hackerrank import ( "errors" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func CompareTriplets(a []int, b []int) ([]int, error) { @@ -27,7 +27,7 @@ func CompareTriplets(a []int, b []int) ([]int, error) { } } - utils.Info("SolveMeFirst answer => %v", awards) + log.Info("SolveMeFirst answer => %v", awards) return awards, nil } diff --git a/exercises/hackerrank/warmup/diagonalDifference.go b/exercises/hackerrank/warmup/diagonalDifference.go index 9510d8d..7ca4c30 100644 --- a/exercises/hackerrank/warmup/diagonalDifference.go +++ b/exercises/hackerrank/warmup/diagonalDifference.go @@ -7,7 +7,7 @@ package hackerrank import ( "math" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func DiagonalDifference(arr [][]int) int { @@ -24,8 +24,8 @@ func DiagonalDifference(arr [][]int) int { } } - utils.Info("diag1 => %d", diag1) - utils.Info("diag2 => %d", diag2) + log.Info("diag1 => %d", diag1) + log.Info("diag2 => %d", diag2) return int(math.Abs(float64(diag1 - diag2))) } diff --git a/exercises/hackerrank/warmup/plusMinus.go b/exercises/hackerrank/warmup/plusMinus.go index 8cd57c2..34c69ad 100644 --- a/exercises/hackerrank/warmup/plusMinus.go +++ b/exercises/hackerrank/warmup/plusMinus.go @@ -8,7 +8,7 @@ import ( "fmt" "strings" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func PlusMinus(arr []int) string { @@ -37,7 +37,7 @@ func PlusMinus(arr []int) string { answer := strings.Join(result, "\n") - utils.Info("PlusMinus answer => %s", answer) + log.Info("PlusMinus answer => %s", answer) return answer } diff --git a/exercises/hackerrank/warmup/simpleArraySum.go b/exercises/hackerrank/warmup/simpleArraySum.go index dcbea35..fefd25b 100644 --- a/exercises/hackerrank/warmup/simpleArraySum.go +++ b/exercises/hackerrank/warmup/simpleArraySum.go @@ -4,9 +4,7 @@ package hackerrank -import ( - utils "gon.cl/algorithms/utils" -) +import "gon.cl/algorithms/utils/log" func SimpleArraySum(arr []int) int { acum := 0 @@ -15,7 +13,7 @@ func SimpleArraySum(arr []int) int { acum += arr[i] } - utils.Info("SimpleArraySum answer => %d", acum) + log.Info("SimpleArraySum answer => %d", acum) return acum } diff --git a/exercises/hackerrank/warmup/solveMeFirst.go b/exercises/hackerrank/warmup/solveMeFirst.go index c2e48bd..6488db9 100644 --- a/exercises/hackerrank/warmup/solveMeFirst.go +++ b/exercises/hackerrank/warmup/solveMeFirst.go @@ -4,15 +4,13 @@ package hackerrank -import ( - utils "gon.cl/algorithms/utils" -) +import "gon.cl/algorithms/utils/log" func SolveMeFirst(a int, b int) int { var answer = a + b - utils.Info("SolveMeFirst answer => %d", answer) + log.Info("SolveMeFirst answer => %d", answer) return answer } diff --git a/exercises/hackerrank/warmup/staircase.go b/exercises/hackerrank/warmup/staircase.go index be6cadf..757bf12 100644 --- a/exercises/hackerrank/warmup/staircase.go +++ b/exercises/hackerrank/warmup/staircase.go @@ -7,7 +7,7 @@ package hackerrank import ( "strings" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Staircase(n int) string { @@ -28,7 +28,7 @@ func Staircase(n int) string { result = append(result, line) } - utils.Info("Staircase answer => %v", result) + log.Info("Staircase answer => %v", result) return strings.Join(result, "\n") } diff --git a/exercises/hackerrank/warmup/timeConversion.go b/exercises/hackerrank/warmup/timeConversion.go index 377acfc..1caf9ab 100644 --- a/exercises/hackerrank/warmup/timeConversion.go +++ b/exercises/hackerrank/warmup/timeConversion.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func TimeConversion(s string) string { @@ -32,7 +32,7 @@ func TimeConversion(s string) string { conversion := strings.Join(time, ":") - utils.Info("TimeConversion answer => %s", conversion) + log.Info("TimeConversion answer => %s", conversion) return conversion } diff --git a/exercises/problem0000.go b/exercises/problem0000.go index 6d6b960..5b4b809 100644 --- a/exercises/problem0000.go +++ b/exercises/problem0000.go @@ -4,15 +4,13 @@ package exercises -import ( - utils "gon.cl/algorithms/utils" -) +import "gon.cl/algorithms/utils/log" func Problem0000() int { var answer int - utils.Info("Problem0000 answer => %d", answer) + log.Info("Problem0000 answer => %d", answer) return answer } diff --git a/exercises/projecteuler/helpers/divisors.go b/exercises/projecteuler/helpers/divisors.go index 9553438..1ccee91 100644 --- a/exercises/projecteuler/helpers/divisors.go +++ b/exercises/projecteuler/helpers/divisors.go @@ -4,7 +4,7 @@ import ( "math" "sort" - "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) type Factor struct { @@ -28,7 +28,7 @@ func Divisors(target int) []int { return divs } - utils.Debug("Find divisors of %d", target) + log.Debug("Find divisors of %d", target) // fast divisors finding loop i := int(2) @@ -50,11 +50,11 @@ func Divisors(target int) []int { } divs = append(divs, target) - utils.Debug("collected divisors %x", divs) + log.Debug("collected divisors %x", divs) // sort divisors sort.Slice(divs, func(i, j int) bool { return divs[i] < divs[j] }) - utils.Debug("sorted divisors %x", divs) + log.Debug("sorted divisors %x", divs) return divs } diff --git a/exercises/projecteuler/helpers/numberToWord.go b/exercises/projecteuler/helpers/numberToWord.go index 40ef057..0d86b30 100644 --- a/exercises/projecteuler/helpers/numberToWord.go +++ b/exercises/projecteuler/helpers/numberToWord.go @@ -4,7 +4,7 @@ import ( "fmt" "math/big" - "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) const _CENTS_ = "hundred" @@ -70,7 +70,7 @@ func NumberToWord(value big.Int) (string, bool) { dec, unit = dec.DivMod(&value, div, unit) dec = dec.Mul(dec, big.NewInt((10))) - utils.Debug("dec => %s | div => %s | unit => %s", + log.Debug("dec => %s | div => %s | unit => %s", dec.Text(__NUMERIC_BASE__), div.Text(__NUMERIC_BASE__), unit.Text(__NUMERIC_BASE__), @@ -96,7 +96,7 @@ func NumberToWord(value big.Int) (string, bool) { } last, err := NumberToWord(*rest) - utils.Debug("err => %t", err) // in bounds, never happens + log.Debug("err => %t", err) // in bounds, never happens return fmt.Sprintf("%s %s and %s", dictionary[cent.Text(__NUMERIC_BASE__)], diff --git a/exercises/projecteuler/helpers/wordScore.go b/exercises/projecteuler/helpers/wordScore.go index a9a6487..5081f1f 100644 --- a/exercises/projecteuler/helpers/wordScore.go +++ b/exercises/projecteuler/helpers/wordScore.go @@ -1,8 +1,6 @@ package helpers -import ( - "gon.cl/algorithms/utils" -) +import "gon.cl/algorithms/utils/log" var _scoreLetter = map[rune]int{ 'A': 1, @@ -38,7 +36,7 @@ func WordScore(word string) int { count := 0 for i, c := range word { - utils.Debug("%d => %c", i, c) + log.Debug("%d => %c", i, c) score, exist := _scoreLetter[c] diff --git a/exercises/projecteuler/lib/BNodeBuilder.go b/exercises/projecteuler/lib/BNodeBuilder.go index 32a44f7..2a7cedc 100644 --- a/exercises/projecteuler/lib/BNodeBuilder.go +++ b/exercises/projecteuler/lib/BNodeBuilder.go @@ -1,6 +1,6 @@ package lib -import "gon.cl/algorithms/utils" +import "gon.cl/algorithms/utils/log" func buildBNodeTreeRecursive( dataTree [][]int, @@ -16,12 +16,12 @@ func buildBNodeTreeRecursive( i+1 <= len(dataTree)-1 && j+1 <= len(dataTree[i+1])-1 { left, err := buildBNodeTreeRecursive(dataTree, i+1, j) - utils.Debug("left: %v | err: %t", left, err) + log.Debug("left: %v | err: %t", left, err) resultNode.setLeft(left) right, err := buildBNodeTreeRecursive(dataTree, i+1, j+1) - utils.Debug("right: %v | err: %t", left, err) + log.Debug("right: %v | err: %t", left, err) resultNode.setRight(right) @@ -55,12 +55,12 @@ func buildBNodeTreeWeigthRecursive( var err bool left, leafCollector, err = buildBNodeTreeWeigthRecursive(dataTree, i+1, j, resultNode, leafCollector) - utils.Debug("left: %v | err: %t | leavesCarry: %v", left, err, leafCollector) + log.Debug("left: %v | err: %t | leavesCarry: %v", left, err, leafCollector) resultNode.setLeft(left) right, leafCollector, err = buildBNodeTreeWeigthRecursive(dataTree, i+1, j+1, resultNode, leafCollector) - utils.Debug("right: %v | err: %t | leavesCarry: %v", left, err, leafCollector) + log.Debug("right: %v | err: %t | leavesCarry: %v", left, err, leafCollector) resultNode.setRight(right) diff --git a/exercises/projecteuler/problem0001.go b/exercises/projecteuler/problem0001.go index 09c57b7..8b7d476 100644 --- a/exercises/projecteuler/problem0001.go +++ b/exercises/projecteuler/problem0001.go @@ -5,7 +5,7 @@ package projecteuler import ( - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0001(top int) int { @@ -16,11 +16,11 @@ func Problem0001(top int) int { total += i - utils.Debug("Problem0001: STEP: %d => TOTAL: %d", i, total) + log.Debug("Problem0001: STEP: %d => TOTAL: %d", i, total) } } - utils.Info("Problem0001 result: %d", total) + log.Info("Problem0001 result: %d", total) return total } diff --git a/exercises/projecteuler/problem0002.go b/exercises/projecteuler/problem0002.go index 2889f8b..c57af11 100644 --- a/exercises/projecteuler/problem0002.go +++ b/exercises/projecteuler/problem0002.go @@ -5,7 +5,7 @@ package projecteuler import ( - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0002(top int) int { @@ -20,7 +20,7 @@ func Problem0002(top int) int { for ok := true; ok; ok = fibo < top { fibo = last2 + last1 - utils.Debug("Fibonacci (%d) = %d", i, fibo) + log.Debug("Fibonacci (%d) = %d", i, fibo) // acumulate sum of event terms if fibo%2 == 0 { @@ -33,7 +33,7 @@ func Problem0002(top int) int { i += 1 } - utils.Info("Problem0002 result: %d", evenSum) + log.Info("Problem0002 result: %d", evenSum) return evenSum } diff --git a/exercises/projecteuler/problem0003.go b/exercises/projecteuler/problem0003.go index 5216bdd..de04ce1 100644 --- a/exercises/projecteuler/problem0003.go +++ b/exercises/projecteuler/problem0003.go @@ -6,7 +6,7 @@ package projecteuler import ( "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0003(top int) int { @@ -14,14 +14,14 @@ func Problem0003(top int) int { divs := helpers.Divisors(top) - utils.Info("Divisors(%d) = %v \n", top, divs) + log.Info("Divisors(%d) = %v \n", top, divs) var i = len(divs) - 1 for ok := true; ok; ok = i >= 0 && maxPrimeFactor == 0 { prime := helpers.IsPrime(divs[i]) - utils.Debug("%d is Prime? => %t \n", divs[i], prime) + log.Debug("%d is Prime? => %t \n", divs[i], prime) if prime { maxPrimeFactor = divs[i] @@ -30,7 +30,7 @@ func Problem0003(top int) int { i -= 1 } - utils.Info("maxPrimeFactor is %d \n", maxPrimeFactor) + log.Info("maxPrimeFactor is %d \n", maxPrimeFactor) return maxPrimeFactor } diff --git a/exercises/projecteuler/problem0004.go b/exercises/projecteuler/problem0004.go index af9e508..5bb110d 100644 --- a/exercises/projecteuler/problem0004.go +++ b/exercises/projecteuler/problem0004.go @@ -6,7 +6,7 @@ package projecteuler import ( "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0004(bottom int, top int) int { @@ -17,7 +17,7 @@ func Problem0004(bottom int, top int) int { var foundPalindrome int var cycles = 0 - utils.Info("Initializing Problem 0004") + log.Info("Initializing Problem 0004") i = top for i >= bottom { @@ -27,7 +27,7 @@ func Problem0004(bottom int, top int) int { cycles += 1 if helpers.IsPalindrome(j * i) { - utils.Debug("FOUND %d x %d = %d is Palindrome", i, j, i*j) + log.Debug("FOUND %d x %d = %d is Palindrome", i, j, i*j) if foundPalindrome == 0 || i*j > foundPalindrome { foundi = i @@ -43,7 +43,7 @@ func Problem0004(bottom int, top int) int { i -= 1 } - utils.Info("Problem0004 Largest Palindrome => %d 𝗑 %d = %d in %d cycles", foundi, foundj, foundPalindrome, cycles) + log.Info("Problem0004 Largest Palindrome => %d 𝗑 %d = %d in %d cycles", foundi, foundj, foundPalindrome, cycles) return foundPalindrome } diff --git a/exercises/projecteuler/problem0005.go b/exercises/projecteuler/problem0005.go index c8997c0..f6a28e7 100644 --- a/exercises/projecteuler/problem0005.go +++ b/exercises/projecteuler/problem0005.go @@ -8,7 +8,7 @@ import ( "math" "gon.cl/algorithms/exercises/projecteuler/helpers" - "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func primeFactorListCollection(factors []int) map[int]int { @@ -19,10 +19,10 @@ func primeFactorListCollection(factors []int) map[int]int { if ok { collection[factor] += 1 - utils.Debug("Factor %d with quantity %d found in %v", factor, quantity, collection) + log.Debug("Factor %d with quantity %d found in %v", factor, quantity, collection) } else { collection[factor] = 1 - utils.Debug("Factor %d with quantity not found in %v", factor, collection) + log.Debug("Factor %d with quantity not found in %v", factor, collection) } } @@ -39,11 +39,11 @@ func Problem0005(bottom int, top int) int { for i := bottom; i <= top; i++ { primeFactorList, subCycles := helpers.PrimeFactors(i) cycles += subCycles - utils.Info("Prime Factors of %d list => %v", i, primeFactorList) + log.Info("Prime Factors of %d list => %v", i, primeFactorList) primeFactorMap := primeFactorListCollection(primeFactorList) cycles += len(primeFactorList) - utils.Info("Prime Factors of %d grouped => %v", i, primeFactorMap) + log.Info("Prime Factors of %d grouped => %v", i, primeFactorMap) for factor, quantity := range primeFactorMap { cycles += 1 @@ -58,7 +58,7 @@ func Problem0005(bottom int, top int) int { } - utils.Info("Minimum Prime Factors of grouped until %d => %v", i, minimumPrimeFactors) + log.Info("Minimum Prime Factors of grouped until %d => %v", i, minimumPrimeFactors) } for factor, quantity := range minimumPrimeFactors { @@ -66,8 +66,8 @@ func Problem0005(bottom int, top int) int { answer *= int(math.Pow(float64(factor), float64(quantity))) } - utils.Info("Problem 0005: Minimum Prime Factors from %d to %d => %v in %d cycles", bottom, top, minimumPrimeFactors, cycles) - utils.Info("Problem 0005: Solution: %d in %d cycles", answer, cycles) + log.Info("Problem 0005: Minimum Prime Factors from %d to %d => %v in %d cycles", bottom, top, minimumPrimeFactors, cycles) + log.Info("Problem 0005: Solution: %d in %d cycles", answer, cycles) return answer } diff --git a/exercises/projecteuler/problem0005_brute_force.go b/exercises/projecteuler/problem0005_brute_force.go index 0a98feb..541d62f 100644 --- a/exercises/projecteuler/problem0005_brute_force.go +++ b/exercises/projecteuler/problem0005_brute_force.go @@ -1,7 +1,7 @@ package projecteuler import ( - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0005BruteForce(bottom int, top int, startFrom int) int { @@ -22,7 +22,7 @@ func Problem0005BruteForce(bottom int, top int, startFrom int) int { fail = test%i != 0 - utils.Debug("%d divisible by %d (remainder: %d => %t)", test, i, test%i, fail) + log.Debug("%d divisible by %d (remainder: %d => %t)", test, i, test%i, fail) i += 1 } @@ -36,7 +36,7 @@ func Problem0005BruteForce(bottom int, top int, startFrom int) int { test += 1 } - utils.Info("Problem0005 answer => %d divisible by any element beetwen %d and %d", answer, bottom, top) + log.Info("Problem0005 answer => %d divisible by any element beetwen %d and %d", answer, bottom, top) return answer } diff --git a/exercises/projecteuler/problem0006.go b/exercises/projecteuler/problem0006.go index 70d410a..f455df7 100644 --- a/exercises/projecteuler/problem0006.go +++ b/exercises/projecteuler/problem0006.go @@ -7,7 +7,7 @@ package projecteuler import ( "math" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func powInt(x, y int) int { @@ -32,13 +32,13 @@ func Problem0006() int { squareOfSum = powInt(baseForSquareOfSum, 2) - utils.Info("Sum of first %d squares = %d", top, sumOfSquares) - utils.Info("Base for Square Of Sum of first %d = %d", top, baseForSquareOfSum) - utils.Info("Square Of Sum of first %d = %d", top, squareOfSum) + log.Info("Sum of first %d squares = %d", top, sumOfSquares) + log.Info("Base for Square Of Sum of first %d = %d", top, baseForSquareOfSum) + log.Info("Square Of Sum of first %d = %d", top, squareOfSum) answer = squareOfSum - sumOfSquares - utils.Info("Problem0006 answer => %d - %d = %d", squareOfSum, sumOfSquares, answer) + log.Info("Problem0006 answer => %d - %d = %d", squareOfSum, sumOfSquares, answer) return squareOfSum - sumOfSquares } diff --git a/exercises/projecteuler/problem0007.go b/exercises/projecteuler/problem0007.go index 56cb7af..54e493f 100644 --- a/exercises/projecteuler/problem0007.go +++ b/exercises/projecteuler/problem0007.go @@ -6,7 +6,7 @@ package projecteuler import ( helpers "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0007(top int) int { @@ -22,7 +22,7 @@ func Problem0007(top int) int { if helpers.IsPrime(j) { primes = append(primes, j) - utils.Debug("Prime found %d put in position: %d", j, len(primes)) + log.Debug("Prime found %d put in position: %d", j, len(primes)) } j = 2*i + 1 @@ -32,7 +32,7 @@ func Problem0007(top int) int { cycles := i - utils.Info("Problem0007 answer => %d in %d cycles", answer, cycles) + log.Info("Problem0007 answer => %d in %d cycles", answer, cycles) return answer } diff --git a/exercises/projecteuler/problem0008.go b/exercises/projecteuler/problem0008.go index d303b6c..1efc68d 100644 --- a/exercises/projecteuler/problem0008.go +++ b/exercises/projecteuler/problem0008.go @@ -9,7 +9,7 @@ import ( "strings" "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) const __BASE__ = 10 @@ -39,14 +39,14 @@ func Problem0008(numberInput string) int { } var currentProduct = helpers.Product(digitsSet) - utils.Debug("Product beetwen %d and %d <%d> is: %d", i, i+interval, digitsSet, currentProduct) + log.Debug("Product beetwen %d and %d <%d> is: %d", i, i+interval, digitsSet, currentProduct) if currentProduct > greatest { greatest = currentProduct } } - utils.Info("Problem0008 => The the greatest product of %d consecutive digits is: %d", interval, greatest) + log.Info("Problem0008 => The the greatest product of %d consecutive digits is: %d", interval, greatest) return greatest } diff --git a/exercises/projecteuler/problem0009.go b/exercises/projecteuler/problem0009.go index 7bf18d4..dcce1d8 100644 --- a/exercises/projecteuler/problem0009.go +++ b/exercises/projecteuler/problem0009.go @@ -7,7 +7,7 @@ package projecteuler import ( "math" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func IsPythagoreanTriplet(a int, b int, c int) bool { @@ -38,10 +38,10 @@ func Problem0009() int { for a < b && b < c && !found { - utils.Debug("Pythagorean triplet? a = %d b = %d c = %d", a, b, c) + log.Debug("Pythagorean triplet? a = %d b = %d c = %d", a, b, c) if IsPythagoreanTriplet(a, b, c) { - utils.Debug("FOUND: a = %d b = %d c = %d => %t", a, b, c, found) + log.Debug("FOUND: a = %d b = %d c = %d => %t", a, b, c, found) foundTriplet = triplet{a: a, b: b, c: c} found = true } @@ -53,14 +53,14 @@ func Problem0009() int { a += 1 } - utils.Info("FOUND: a = %d b = %d c = %d => %.0f + %.0f = %.0f", + log.Info("FOUND: a = %d b = %d c = %d => %.0f + %.0f = %.0f", foundTriplet.a, foundTriplet.b, foundTriplet.c, math.Pow(float64(foundTriplet.a), 2), math.Pow(float64(foundTriplet.b), 2), math.Pow(float64(foundTriplet.c), 2)) answer = foundTriplet.a * foundTriplet.b * foundTriplet.c - utils.Info("Problem0009 answer => %d", answer) + log.Info("Problem0009 answer => %d", answer) return answer } diff --git a/exercises/projecteuler/problem0010.go b/exercises/projecteuler/problem0010.go index 850a1a2..f51f298 100644 --- a/exercises/projecteuler/problem0010.go +++ b/exercises/projecteuler/problem0010.go @@ -6,7 +6,7 @@ package projecteuler import ( "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0010(bottom int, top int) int { @@ -20,17 +20,17 @@ func Problem0010(bottom int, top int) int { for i <= top { if helpers.IsPrime(i) { primes = append(primes, i) - utils.Debug("Prime found %d put in position: %d", i, len(primes)) + log.Debug("Prime found %d put in position: %d", i, len(primes)) } i += 2 } answer = helpers.Sum(primes) - utils.Info("primes count: %d", len(primes)) - utils.Info("Sum of primes below ${top} is: ${sum(primes)}") + log.Info("primes count: %d", len(primes)) + log.Info("Sum of primes below ${top} is: ${sum(primes)}") - utils.Info("Problem0010 answer => Sum of primes below %d = %d", top, answer) + log.Info("Problem0010 answer => Sum of primes below %d = %d", top, answer) return answer } diff --git a/exercises/projecteuler/problem0011.go b/exercises/projecteuler/problem0011.go index 9b8a974..cc424a3 100644 --- a/exercises/projecteuler/problem0011.go +++ b/exercises/projecteuler/problem0011.go @@ -6,7 +6,7 @@ package projecteuler import ( helpers "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0011(matrix [][]int, interval int) (int, bool) { @@ -21,14 +21,14 @@ func Problem0011(matrix [][]int, interval int) (int, bool) { for i := 0; i < matrixLimit; i += 1 { for j := 0; j < matrixLimit; j += 1 { - utils.Debug("start point => i: %d, j: %d", i, j) + log.Debug("start point => i: %d, j: %d", i, j) // reset diagonals var diag1Acum = 1 var diag2Acum = 1 for k := 0; k < quadrantSize; k += 1 { - utils.Debug("diag1 coordinate: (i, j) = (%d, %d)", i+k, j+k) - utils.Debug("diag2 coordinate: (i, j) = (%d, %d)", i+k, j+(quadrantSize-1)-k) + log.Debug("diag1 coordinate: (i, j) = (%d, %d)", i+k, j+k) + log.Debug("diag2 coordinate: (i, j) = (%d, %d)", i+k, j+(quadrantSize-1)-k) diag1Acum *= matrix[i+k][j+k] diag2Acum *= matrix[i+k][j+(quadrantSize-1)-k] @@ -40,8 +40,8 @@ func Problem0011(matrix [][]int, interval int) (int, bool) { var verticalAcum = 1 var horizontalAcum = 1 for l := 0; l < quadrantSize; l += 1 { - utils.Debug("vertical coordinate: (i, j) = (%d, %d)", i+k, j+l) - utils.Debug("horizontal coordinate: (i, j) = (%d, %d)", i+l, j+k) + log.Debug("vertical coordinate: (i, j) = (%d, %d)", i+k, j+l) + log.Debug("horizontal coordinate: (i, j) = (%d, %d)", i+l, j+k) verticalAcum *= matrix[i+k][j+l] horizontalAcum *= matrix[i+l][j+k] @@ -53,7 +53,7 @@ func Problem0011(matrix [][]int, interval int) (int, bool) { } } - utils.Info("Problem0011 greatest => %d", greatest) + log.Info("Problem0011 greatest => %d", greatest) return greatest, false } diff --git a/exercises/projecteuler/problem0012.go b/exercises/projecteuler/problem0012.go index f0626ce..fc238f7 100644 --- a/exercises/projecteuler/problem0012.go +++ b/exercises/projecteuler/problem0012.go @@ -6,7 +6,7 @@ package projecteuler import ( "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0012(top int) int { @@ -19,12 +19,12 @@ func Problem0012(top int) int { var listOfDivisors = helpers.Divisors(triangular) amountOfDivisors = len(listOfDivisors) - utils.Debug("Triangular number: %d has %d divisors", triangular, amountOfDivisors) + log.Debug("Triangular number: %d has %d divisors", triangular, amountOfDivisors) i += 1 } - utils.Info("Problem0012 answer => %d", triangular) + log.Info("Problem0012 answer => %d", triangular) return triangular } diff --git a/exercises/projecteuler/problem0013.go b/exercises/projecteuler/problem0013.go index 7c0bd68..8ff7412 100644 --- a/exercises/projecteuler/problem0013.go +++ b/exercises/projecteuler/problem0013.go @@ -8,7 +8,7 @@ package projecteuler import ( "math/big" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0013(inputListOfBigNumbers []string) string { @@ -24,20 +24,20 @@ func Problem0013(inputListOfBigNumbers []string) string { var bignum, ok = new(big.Int).SetString(inputListOfBigNumbers[i], 0) listOfBigNumbers = append(listOfBigNumbers, bignum) - utils.Debug("new bigNumber: %s | %t", bignum.Text(BASE), ok) + log.Debug("new bigNumber: %s | %t", bignum.Text(BASE), ok) answer = answer.Add(answer, bignum) } - utils.Debug("listOfBigNumbers: %v", listOfBigNumbers) + log.Debug("listOfBigNumbers: %v", listOfBigNumbers) for answer.Cmp(bigTop) >= 1 { answer = answer.Div(answer, big.NewInt(BASE)) - utils.Debug("Answer reduction: %s", answer.String()) + log.Debug("Answer reduction: %s", answer.String()) } - utils.Info("Problem0013 answer => %v", answer) + log.Info("Problem0013 answer => %v", answer) return answer.Text(BASE) } diff --git a/exercises/projecteuler/problem0014.go b/exercises/projecteuler/problem0014.go index f7041aa..8fb4f1d 100644 --- a/exercises/projecteuler/problem0014.go +++ b/exercises/projecteuler/problem0014.go @@ -6,7 +6,7 @@ package projecteuler import ( "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0014(bottom int, top int) int { @@ -16,18 +16,18 @@ func Problem0014(bottom int, top int) int { for i := bottom; i < top; i += 1 { var sequence = helpers.CollatzSequence(i) - utils.Debug("sequence of %d: %v", i, sequence) + log.Debug("sequence of %d: %v", i, sequence) if len(sequence) > len(maxSequence) { maxSequence = sequence } } - utils.Info("Large sequence found: ${maxSequence} has ${maxSequence.length} elements") + log.Info("Large sequence found: ${maxSequence} has ${maxSequence.length} elements") // return firt element answer = maxSequence[0] - utils.Info("Problem0014 answer => %d", answer) + log.Info("Problem0014 answer => %d", answer) return answer } diff --git a/exercises/projecteuler/problem0015.go b/exercises/projecteuler/problem0015.go index 05b47c0..94ea7d8 100644 --- a/exercises/projecteuler/problem0015.go +++ b/exercises/projecteuler/problem0015.go @@ -6,7 +6,7 @@ package projecteuler import ( helpers "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0015(gridSide int) int { @@ -23,10 +23,10 @@ func Problem0015(gridSide int) int { vertexMatrix[i][j] = upperParent + leftParent } } - utils.Debug("Paths found: ${vertexMatrix[gridSide][gridSide]}") - utils.Debug("vertexMatrix: %v", vertexMatrix) + log.Debug("Paths found: ${vertexMatrix[gridSide][gridSide]}") + log.Debug("vertexMatrix: %v", vertexMatrix) - utils.Info("Problem0015 answer => %d", answer) + log.Info("Problem0015 answer => %d", answer) return vertexMatrix[gridSide][gridSide] } diff --git a/exercises/projecteuler/problem0016.go b/exercises/projecteuler/problem0016.go index 043f4e1..7f4efa8 100644 --- a/exercises/projecteuler/problem0016.go +++ b/exercises/projecteuler/problem0016.go @@ -21,7 +21,7 @@ import ( "strings" "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) const __NUMERIC_BASE__ = 10 @@ -35,7 +35,7 @@ func Problem0016(base int, exponent int) string { answer := helpers.BigSumMany(chars) - utils.Info("Problem0016 answer => %s", answer) + log.Info("Problem0016 answer => %s", answer) return answer } diff --git a/exercises/projecteuler/problem0017.go b/exercises/projecteuler/problem0017.go index 6214951..dac07f6 100644 --- a/exercises/projecteuler/problem0017.go +++ b/exercises/projecteuler/problem0017.go @@ -9,7 +9,7 @@ import ( "regexp" "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0017(init int, last int) int { @@ -29,10 +29,10 @@ func Problem0017(init int, last int) int { acum += len(replaced) - utils.Debug("acum: %d <= (%d) word: %s", acum, i, word) + log.Debug("acum: %d <= (%d) word: %s", acum, i, word) } - utils.Info("Problem0017 answer => %d", acum) + log.Info("Problem0017 answer => %d", acum) return acum } diff --git a/exercises/projecteuler/problem0018.go b/exercises/projecteuler/problem0018.go index 809e7c8..710af6d 100644 --- a/exercises/projecteuler/problem0018.go +++ b/exercises/projecteuler/problem0018.go @@ -7,7 +7,7 @@ package projecteuler import ( "gon.cl/algorithms/exercises/projecteuler/helpers" "gon.cl/algorithms/exercises/projecteuler/lib" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0018(tree lib.Tree) int { @@ -16,8 +16,8 @@ func Problem0018(tree lib.Tree) int { answer, err := helpers.IntMaxOfMany(tree.GetLeafs()) - utils.Info("Problem0018 answer => leafs: %d", len(tree.GetLeafs())) - utils.Info("Problem0018 answer => Max leaf: %d | err: %v", answer, err) + log.Info("Problem0018 answer => leafs: %d", len(tree.GetLeafs())) + log.Info("Problem0018 answer => Max leaf: %d | err: %v", answer, err) return answer } diff --git a/exercises/projecteuler/problem0019.go b/exercises/projecteuler/problem0019.go index 9613010..c80dcdf 100644 --- a/exercises/projecteuler/problem0019.go +++ b/exercises/projecteuler/problem0019.go @@ -6,7 +6,7 @@ package projecteuler import ( constants "gon.cl/algorithms/exercises/projecteuler/constants" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) const __FEBRUARY_KEY__ = "FEBRUARY" @@ -25,7 +25,7 @@ func Problem0019( var leap int if (y%4 == 0 && y%100 != 0) || y%400 == 0 { - utils.Debug("Year %d has leap-day", y) + log.Debug("Year %d has leap-day", y) leap = 1 } else { leap = 0 @@ -34,7 +34,7 @@ func Problem0019( for _, month := range constants.MONTHS_OF_YEAR { days := constants.DAYS_IN_MONTH[month] - utils.Debug("Year %d| Month: %s | days %d", y, month, days) + log.Debug("Year %d| Month: %s | days %d", y, month, days) accumulatedRemainder += days % 7 if accumulatedRemainder%7 == dayOfWeek { @@ -46,7 +46,7 @@ func Problem0019( } } - utils.Info("Problem0019 result: (%d - %d) => %d", resultCount, excess, resultCount-excess) + log.Info("Problem0019 result: (%d - %d) => %d", resultCount, excess, resultCount-excess) return resultCount - excess } diff --git a/exercises/projecteuler/problem0020.go b/exercises/projecteuler/problem0020.go index ae5bdb3..1f37346 100644 --- a/exercises/projecteuler/problem0020.go +++ b/exercises/projecteuler/problem0020.go @@ -15,14 +15,14 @@ import ( "math/big" "gon.cl/algorithms/exercises/projecteuler/helpers" - "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0020(last int) *big.Int { factorial := helpers.BigFactorial(last) - utils.Info("Problem0020 answer => %v", factorial) + log.Info("Problem0020 answer => %v", factorial) return factorial } diff --git a/exercises/projecteuler/problem0020_test.go b/exercises/projecteuler/problem0020_test.go index a865105..1ede870 100644 --- a/exercises/projecteuler/problem0020_test.go +++ b/exercises/projecteuler/problem0020_test.go @@ -14,7 +14,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func TestProblem0020(t *testing.T) { @@ -25,7 +25,7 @@ func TestProblem0020(t *testing.T) { expectedSolution, ok := expectedSolution.SetString("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000", 10) if !ok { - utils.Error("Problem0020: expectedSolution.SetString() failed") + log.Error("Problem0020: expectedSolution.SetString() failed") return } diff --git a/exercises/projecteuler/problem0021.go b/exercises/projecteuler/problem0021.go index a7120af..b48e138 100644 --- a/exercises/projecteuler/problem0021.go +++ b/exercises/projecteuler/problem0021.go @@ -18,7 +18,7 @@ package projecteuler import ( "gon.cl/algorithms/exercises/projecteuler/helpers" - "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0021(start int, limit int) int { @@ -31,12 +31,12 @@ func Problem0021(start int, limit int) int { divs := helpers.Divisors(i) sum := helpers.Sum(divs) - i - utils.Debug("Divisors of %d => %v => Sum = %d", i, divs, sum) + log.Debug("Divisors of %d => %v => Sum = %d", i, divs, sum) cache[i] = sum } - utils.Debug("Problem0021 cache => %d", cache) + log.Debug("Problem0021 cache => %d", cache) for a, b := range cache { if a != b && helpers.AreAmicables(a, b, cache) { @@ -47,7 +47,7 @@ func Problem0021(start int, limit int) int { var answer int - utils.Info("Problem0021 amicables => %v", amicables) + log.Info("Problem0021 amicables => %v", amicables) amicablesList := []int{} for value := range amicables { @@ -56,7 +56,7 @@ func Problem0021(start int, limit int) int { answer = helpers.Sum(amicablesList) - utils.Info("Problem0021 answer => %d", answer) + log.Info("Problem0021 answer => %d", answer) return answer } diff --git a/exercises/projecteuler/problem0022.go b/exercises/projecteuler/problem0022.go index 0902381..696cb79 100644 --- a/exercises/projecteuler/problem0022.go +++ b/exercises/projecteuler/problem0022.go @@ -10,7 +10,7 @@ import ( "sort" "gon.cl/algorithms/exercises/projecteuler/helpers" - "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Problem0022(listOfNames []string) int { @@ -23,7 +23,7 @@ func Problem0022(listOfNames []string) int { answer += (i + 1) * helpers.WordScore(listOfNames[i]) } - utils.Info("Problem0022 answer => %d", answer) + log.Info("Problem0022 answer => %d", answer) return answer } diff --git a/exercises/projecteuler/problem0023.go b/exercises/projecteuler/problem0023.go index 5537355..97573df 100644 --- a/exercises/projecteuler/problem0023.go +++ b/exercises/projecteuler/problem0023.go @@ -7,7 +7,7 @@ package projecteuler import ( "golang.org/x/exp/slices" "gon.cl/algorithms/exercises/projecteuler/helpers" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func Contains[T comparable](s []T, e T) bool { @@ -32,8 +32,8 @@ func Problem0023(underLimit int, superLimit int) int { } } - utils.Info("abundant nums list size => %d", len(abundantNumberList)) - utils.Debug("abundant nums list result => %+v", abundantNumberList) + log.Info("abundant nums list size => %d", len(abundantNumberList)) + log.Debug("abundant nums list result => %+v", abundantNumberList) var sumsAbundantNums = []int{} @@ -48,15 +48,15 @@ func Problem0023(underLimit int, superLimit int) int { } } - utils.Info("sumsAbundantNums size => %d", len(sumsAbundantNums)) - utils.Debug("sumsAbundantNums result => %+v", sumsAbundantNums) + log.Info("sumsAbundantNums size => %d", len(sumsAbundantNums)) + log.Debug("sumsAbundantNums result => %+v", sumsAbundantNums) // filter duplicates slices.Sort(sumsAbundantNums) sumsAbundantNums = slices.Compact(sumsAbundantNums) - utils.Info("filtered sumsAbundantNums size => %d", len(sumsAbundantNums)) - utils.Debug("filtered sumsAbundantNums result => %+v", sumsAbundantNums) + log.Info("filtered sumsAbundantNums size => %d", len(sumsAbundantNums)) + log.Debug("filtered sumsAbundantNums result => %+v", sumsAbundantNums) // All numbers below limit that not present in list of sums of pair of abundant numbers var found = []int{} @@ -67,15 +67,15 @@ func Problem0023(underLimit int, superLimit int) int { } } - utils.Info("found size %d", len(found)) - utils.Debug("found result => %+v", found) + log.Info("found size %d", len(found)) + log.Debug("found result => %+v", found) result := 0 for _, value := range found { result += value } - utils.Info("Problem0023 answer => %d", result) + log.Info("Problem0023 answer => %d", result) return result } diff --git a/exercises/projecteuler/problem0024.go b/exercises/projecteuler/problem0024.go index 621cb92..8c5099e 100644 --- a/exercises/projecteuler/problem0024.go +++ b/exercises/projecteuler/problem0024.go @@ -7,7 +7,7 @@ package projecteuler import ( "strings" - utils "gon.cl/algorithms/utils" + "gon.cl/algorithms/utils/log" ) func factorial(n int) int { @@ -23,21 +23,21 @@ func factorial(n int) int { func permute(symbols string, target int) string { choices := strings.Split(symbols, "") answer := "" - min := 0 + minimum := 0 for len(choices) > 0 { index := 0 combos := factorial(len(choices) - 1) - min += combos - for target > min { + minimum += combos + for target > minimum { index += 1 - min += combos + minimum += combos } answer += choices[index] copy(choices[index:], choices[index+1:]) choices[len(choices)-1] = "" choices = choices[:len(choices)-1] - min -= combos + minimum -= combos } return answer @@ -47,7 +47,7 @@ func Problem0024(inputElements string, inputPermutationToFind int) string { var permutationFound = permute(inputElements, inputPermutationToFind) - utils.Info("Problem0024 answer => %+v", permutationFound) + log.Info("Problem0024 answer => %+v", permutationFound) return permutationFound } diff --git a/utils/logger.go b/utils/log/logger.go similarity index 94% rename from utils/logger.go rename to utils/log/logger.go index ceb7164..9c6dd56 100644 --- a/utils/logger.go +++ b/utils/log/logger.go @@ -1,4 +1,4 @@ -package utils +package log import ( "fmt" @@ -6,6 +6,7 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" + "gon.cl/algorithms/utils" ) const __FALLBACK_LOG_LEVEL__ = "INFO" @@ -42,7 +43,7 @@ func getLogLevel(logLevel string) zapcore.Level { } func init() { - level := getLogLevel(GetEnv("LOG_LEVEL", __FALLBACK_LOG_LEVEL__)) + level := getLogLevel(utils.GetEnv("LOG_LEVEL", __FALLBACK_LOG_LEVEL__)) log := initLoggerZap() @@ -55,7 +56,7 @@ func initLoggerZap() *zap.Logger { cfg := zap.Config{ Encoding: "json", DisableCaller: true, - Level: zap.NewAtomicLevelAt(getLogLevel(GetEnv("LOG_LEVEL", __FALLBACK_LOG_LEVEL__))), + Level: zap.NewAtomicLevelAt(getLogLevel(utils.GetEnv("LOG_LEVEL", __FALLBACK_LOG_LEVEL__))), OutputPaths: []string{"stdout"}, ErrorOutputPaths: []string{"stdout"}, EncoderConfig: zapcore.EncoderConfig{