2025 Day 7 Complete!
This commit is contained in:
@@ -3,10 +3,10 @@ package aoc
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -65,7 +65,7 @@ func Gcd(x, y int) int {
|
||||
// Lcm finds the least common multiple, using gcd
|
||||
func Lcm(a, b int, integers ...int) int {
|
||||
result := a * b / Gcd(a, b)
|
||||
for i := 0; i < len(integers); i++ {
|
||||
for i := range integers {
|
||||
result = Lcm(result, integers[i])
|
||||
}
|
||||
return result
|
||||
@@ -92,8 +92,8 @@ func ArgIsSet(a string) bool {
|
||||
// GetArgValue returns the argument with the asked for key or ""
|
||||
func GetArgValue(a string) string {
|
||||
for i := range os.Args {
|
||||
if strings.HasPrefix(os.Args[i], a+"=") {
|
||||
return strings.TrimPrefix(os.Args[i], a+"=")
|
||||
if ret, ok := strings.CutPrefix(os.Args[i], a+"="); ok {
|
||||
return ret
|
||||
}
|
||||
}
|
||||
return ""
|
||||
@@ -206,8 +206,7 @@ func FileToString(fn string) string {
|
||||
func FileToBytes(fn string) []byte {
|
||||
var c []byte
|
||||
var err error
|
||||
c, err = ioutil.ReadFile(fn)
|
||||
if err != nil {
|
||||
if c, err = os.ReadFile(fn); err != nil {
|
||||
fmt.Println("Unable to read file: " + fn)
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -322,24 +321,16 @@ func StringSliceIndex(h []string, n string) int {
|
||||
|
||||
// StringSliceContains takes a string slice and a string and return true
|
||||
// if the string is in the slice
|
||||
// Created before we had a slices.Contains. Still here for old solutions
|
||||
func StringSliceContains(h []string, n string) bool {
|
||||
for _, v := range h {
|
||||
if v == n {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(h, n)
|
||||
}
|
||||
|
||||
// IntSliceContains takes an int slice and an int and return true
|
||||
// if the int is in the slice
|
||||
// Created before we had a slices.Contains. Still here for old solutions
|
||||
func IntSliceContains(h []int, n int) bool {
|
||||
for _, v := range h {
|
||||
if v == n {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(h, n)
|
||||
}
|
||||
|
||||
// AppendString returns a slice of strings that are base+group[...]
|
||||
@@ -375,7 +366,7 @@ func IntersectStringSlice(list1, list2 []string) []string {
|
||||
// Unique removes all duplicates
|
||||
func UniqueStringSlice(list []string) []string {
|
||||
var ret []string
|
||||
for k := 0; k < len(list); k++ {
|
||||
for k := range list {
|
||||
var dupe bool
|
||||
for j := k; j < len(list); j++ {
|
||||
if list[k] == list[j] {
|
||||
|
||||
Reference in New Issue
Block a user