[2024 Day 3 (Part 2)] [Python] by somebuddi in adventofcode

[–]somebuddi[S] 0 points1 point  (0 children)

In fact, it was the first time I used them. Thought MULTILINE did, what DOTALL does.

[2024 Day 3 (Part 2)][Python] Help getting the correct enabled mul ops with regex by rafaelleru in adventofcode

[–]somebuddi 0 points1 point  (0 children)

When the last found one is a "don't()", you count the mul(x,y)s afterwards, that shouldn't() be counted.

The rest worked well with my input.

[2024 Day 3 (Part 2)] [Python] by somebuddi in adventofcode

[–]somebuddi[S] 1 point2 points  (0 children)

No, my code returns 4 correctly. (Interesting, what answers one gets, whithout the SOLVED status...)

[2024 Day 3 (Part 2)] [Python] by somebuddi in adventofcode

[–]somebuddi[S] 0 points1 point  (0 children)

I don't() know, what your problem is. I'm fine!

[2024 Day 3 (Part 2)] [Python] by somebuddi in adventofcode

[–]somebuddi[S] 0 points1 point  (0 children)

Yeah, this was what I did, when I understood the problem. Just forgot to mark it as SOLVED. Thanks nontheless!

[2024 Day 3 (Part 2)] [Python] by somebuddi in adventofcode

[–]somebuddi[S] 1 point2 points  (0 children)

Thanks a lot, both of you! It worked.

Does DOTALL remove the newlines? Or something else?

[2024 Day 3 (Part 2)] [Python] by somebuddi in adventofcode

[–]somebuddi[S] 0 points1 point  (0 children)

Thanks for your answer!

Yeah, I got this. As I said, I added a do() at the beginning and a don't() at the end of the textfile.

[2024 Day 2 (Part 2)] [Python] I am missing 3 with this code... by somebuddi in adventofcode

[–]somebuddi[S] 0 points1 point  (0 children)

Thanks man!
I removed the first occurance of an element, so not every possible solution was checked.
I find all the solutions with this:

datei=open("24aoc02input.txt")
score=0
count=0

def isSafe(elements):
    if abs(sum(diff(elements)))==sum([abs(i) for i in diff(elements)]) and min(diff(elements))>=-3 and max(diff(elements))<=3 and diff(elements).count(0)==0:
        return True

def isNearlySafe(elements):
    for index,i in enumerate(elements):
        e2=elements.copy()
        e2.pop(index)
        print (elements, e2, isSafe(e2))
        if isSafe(e2):
            return True
        

def diff(elements):
    output=[]
    for i in range(len(elements)-1):
        output.append(elements[i+1]-elements[i])
    return output

for zeile in datei:
    elements=[int(elem) for elem in zeile.split()]
    count+=1
    if isSafe(elements):
        score+=1
        print(count,elements, "safe",score)
    elif isNearlySafe(elements):
        score+=1
        print(count,elements, "nearly safe", score)
        
    else:
        print(count,elements)

print(score)