2024 Day 6 Complete!

This commit is contained in:
2024-12-07 08:09:00 -06:00
parent b852b3951a
commit cf6c7f34f4
6 changed files with 495 additions and 1 deletions

View File

@@ -34,6 +34,21 @@ func NewCoordByteMap() CoordByteMap {
}
}
func (m *CoordByteMap) Copy() *CoordByteMap {
c := CoordByteMap{
Field: make(map[Coordinate]byte),
TLX: m.TLX,
TLY: m.TLY,
BRX: m.BRX,
BRY: m.BRY,
StringEmptyByte: m.StringEmptyByte,
}
for i := range m.Field {
c.Field[i] = m.Field[i]
}
return &c
}
func StringSliceToCoordByteMap(input []string) CoordByteMap {
ret := CoordByteMap{
Field: make(map[Coordinate]byte),
@@ -259,7 +274,7 @@ func (m *CoordByteMap) FindLast(b byte) (Coordinate, error) {
}
}
}
return Coordinate{}, errors.New("Not Found")
return Coordinate{}, errors.New("not found")
}
func (m *CoordByteMap) FindAll(b ...byte) []Coordinate {

View File

@@ -31,6 +31,12 @@ const (
SHRUG = "¯\\_(ツ)_/¯"
)
func CheckErr(err error) {
if err != nil {
panic(err)
}
}
// Fact returns the factorial of the given int
func Fact(x int) int {
var ret int
@@ -402,6 +408,7 @@ func SliceMin(sl []int) int {
return Min(sl[0], sl[1], sl[2:]...)
}
}
func Min(v1, v2 int, vrest ...int) int {
min := v2
if v1 < v2 {
@@ -440,3 +447,17 @@ func Sum(l, h int) int {
func ManhattanDistance(x1, y1, x2, y2 int) int {
return AbsInt(x1-x2) + AbsInt(y1-y2)
}
func PromptUser(text string, required bool) string {
var resp string
fmt.Print(text + ": ")
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
resp = scanner.Text()
}
if resp == "" && required {
fmt.Println("Non-empty response is required")
return PromptUser(text, required)
}
return strings.TrimSpace(resp)
}