2018 day06 solution, patch 2020 scripts missing flag.Parse()

This commit is contained in:
alexchao26
2020-11-29 20:03:29 -05:00
parent f1e7900b8b
commit 1cac95e4f9
31 changed files with 291 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
package util
import (
"math"
)
func PythagoreanDistance(x1, y1, x2, y2 int) float64 {
xDiff := float64(x1 - x2)
yDiff := float64(y1 - y2)
sumOfSquares := math.Pow(xDiff, 2) + math.Pow(yDiff, 2)
return math.Sqrt(sumOfSquares)
}
func ManhattanDistance(x1, y1, x2, y2 int) int {
xDiff := x1 - x2
yDiff := y1 - y2
if xDiff < 0 {
xDiff *= -1
}
if yDiff < 0 {
yDiff *= -1
}
return xDiff + yDiff
}
+14
View File
@@ -0,0 +1,14 @@
package util
import (
"fmt"
"strconv"
)
func StrToInt(in string) int {
num, err := strconv.Atoi(in)
if err != nil {
panic(fmt.Sprintf("converting string to number: %s", err))
}
return num
}