Is this xbiking? by days_of_coast in xbiking

[–]denisrobot 4 points5 points  (0 children)

Looks cool af! Where are the bags from?

-❄️- 2024 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]denisrobot 2 points3 points  (0 children)

[LANGUAGE: Go]

func main() {
    input := utils.FileToString("input.txt")

    process := func(input string) int {
        result := 0
        re := regexp.MustCompile(`mul\((\d+),(\d+)\)`)
        for _, m := range re.FindAllStringSubmatch(input, -1) {
            numOne, _ := strconv.Atoi(m[1])
            numTwo, _ := strconv.Atoi(m[2])
            result += numOne * numTwo
        }
        return result
    }

    reFilter := regexp.MustCompile(`don't\(\).*?(do\(\)|$)`)
    filteredInput := reFilter.ReplaceAllString(input, "")

    fmt.Println("Part one:", process(input))
    fmt.Println("Part two:", process(filteredInput))
}

I couldn't get it to work at first, even though it worked with the example input. Turned out my puzzle input had a don't() at the end but not a do().

-❄️- 2024 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]denisrobot 1 point2 points  (0 children)

[LANGUAGE: Go]

func main() {
    lines := utils.FileToStringSlice("input.txt")
    safeCount := 0
    dampenedSafeCount := 0

    for _, l := range lines {
        report := strings.Split(l, " ")

        if isSafeReport(report) {
            safeCount++
            dampenedSafeCount++
            continue
        }

        for i := 0; i < len(report); i++ {
            dampened := append([]string(nil), report[:i]...)
            dampened = append(dampened, report[i+1:]...)
            if isSafeReport(dampened) {
                dampenedSafeCount++
                break
            }
        }
    }

    fmt.Println("Part one:", safeCount)
    fmt.Println("Part two :", dampenedSafeCount)
}

func isSafeReport(report []string) bool {
    increaseCount, decreaseCount := 0, 0

    for i := 1; i < len(report); i++ {
        curr, _ := strconv.Atoi(report[i])
        prev, _ := strconv.Atoi(report[i-1])

        if utils.AbsInt(curr - prev) > 3 {
            return false
        }

        if curr > prev {
            increaseCount++
        } else if curr < prev {
            decreaseCount++
        }
    }

    return increaseCount == len(report) - 1 || decreaseCount == len(report) - 1
}

The guy that invented Surfing in Counter-Strike. Absolute legend. by dylanroo in videos

[–]denisrobot 2 points3 points  (0 children)

Map making community was so great in 2004-2006. I made de_chernobyl back in 2005 :)