Advent of Code 2024 | Day 07 "Bridge Repair"

  Рет қаралды 2,347

HyperNeutrino

HyperNeutrino

Күн бұрын

Пікірлер: 23
@mattisovereighteen
@mattisovereighteen Ай бұрын
For you, I'm glad you're getting paid by a sponsor. You do great work and you should be paid for it. I'll gladly take the slight annoyance if it means you're benefiting from your own hard work
@SebastianRuhs
@SebastianRuhs Ай бұрын
Thank you for another great explanation of how to solve the puzzle!
@zekrodev
@zekrodev Ай бұрын
Really cool to see that you got a sponsor for the video. WEll deserved payment for the consistently great work.
@hyper-neutrino
@hyper-neutrino Ай бұрын
thanks! also that's monaspace krypton IIRC (monaspace.githubnext.com/)
@kayebennett7867
@kayebennett7867 Ай бұрын
So elegant, I didn't think of looking at the input from end to start... Once you know it, it seems so natural :D
@QuotePilgrim
@QuotePilgrim Ай бұрын
There is no real advantage to going backwards. You can implement the exact same algorithm _she_ implemented in the video by going from the start of the list. Think about it, if you have two lists A and B that are really the exact same list but reversed relative to each other, what the backwards algorithm does to solve list A would be the same thing the forwards algorithm does to solve list B and vice versa.
@hyper-neutrino
@hyper-neutrino Ай бұрын
this is untrue because the operators are left-to-right, also *she. i may be misunderstanding your approach here though so if you implemented it this way i would like to see how you solved it
@QuotePilgrim
@QuotePilgrim Ай бұрын
@@hyper-neutrino Oh, right, computer science degree, I should have known, my bad. Anyway yeah I just forgot to consider that because there's no order of operations it matters whether you go forwards or backwards. If it was like a real mathematical equation, if you flip the whole thing around you still get the same result. 2 + 3 * 4 + 5 and 5 + 4 * 3 + 2 are the same thing in math so my brain just assumed it to be true for the puzzle. Of course it's not, I was just being dumb.
@kayebennett7867
@kayebennett7867 Ай бұрын
​@@QuotePilgrim Also, even if the list were analysed by operation precedence, this would be wrong once you consider non-commutative operations (such as concatenation). The only reason why handling the input in reverse is more useful than forward is because two of the operations (multiplication and concatenation, and technically addition also) don't have a well-defined inverse operation, which allows us to reduce the amount of nodes to search in the ternary tree.
@pranavtaysheti7858
@pranavtaysheti7858 Ай бұрын
But how did elephant 🐘 run away with operator?
@TheFrogfather1
@TheFrogfather1 Ай бұрын
It's a good idea not to try to overanalyse the stories :P
@shrugalic
@shrugalic Ай бұрын
I did it the exact way you showed first, but in Rust, so it's not nearly as compact. I like how concise Python is
@TheFrogfather1
@TheFrogfather1 Ай бұрын
The length of my Object Pascal solution would make you cry :P
@shrugalic
@shrugalic Ай бұрын
@ Oh. My second programming language was Pascal. The memories…
@TheFrogfather1
@TheFrogfather1 Ай бұрын
@@shrugalic The day job is React/JS so AOC is about the only time I use Pascal these days.
@galactic_fx
@galactic_fx Ай бұрын
chapters!
@hyper-neutrino
@hyper-neutrino Ай бұрын
yeah, i realize i've been forgetting to put those in. i remembered because i had a sponsor segment and so i wanted to let people skip it more easily :)
@shrugalic
@shrugalic Ай бұрын
@@hyper-neutrinoappreciated, ty
@rastislavsvoboda4363
@rastislavsvoboda4363 Ай бұрын
clever, going backwards I'm just going "straightforward" ;-) def matches1(target, array): if len(array) == 1: return target == array[0] a = array[0] b = array[1] tail = array[2:] return (matches1(target, [a + b] + tail) or matches1(target, [a * b] + tail)) def matches2(target, array): if len(array) == 1: return target == array[0] a = array[0] b = array[1] tail = array[2:] return (matches2(target, [a + b] + tail) or matches2(target, [a * b] + tail) or matches2(target, [int(str(a) + str(b))] + tail))
@avagata9309
@avagata9309 Ай бұрын
so a DFS
@hyper-neutrino
@hyper-neutrino Ай бұрын
yep
@deathxunnat4693
@deathxunnat4693 Ай бұрын
whats wrong with my code from collections import deque def read_input(file_path): result = {} with open(file_path, 'r') as file: for line in file: key, value = line.split(':') key = int(key.strip()) value = deque(map(int, value.strip().split())) result[key] = value return result def re(a, b): if len(b) == 1: return b[0] f = b.popleft() s = b.popleft() # Addition sum_val = f + s b.appendleft(sum_val) add = re(a, b) if add == a: return a b.popleft() # Subtraction diff_val = f - s b.appendleft(diff_val) subtract = re(a, b) if subtract == a: return a b.popleft() # Multiplication prod = f * s b.appendleft(prod) product = re(a, b) if product == a: return a b.popleft() # Division (ensure no division by zero) if s != 0: div_val = f // s b.appendleft(div_val) divide = re(a, b) if divide == a: return a b.popleft() # Restore the deque b.appendleft(s) b.appendleft(f) return prod def ist(p): return re(p[0], p[1]) == p[0] def main(): file_path = 's.txt' data = read_input(file_path) # Print the map to verify the result ss = 0 for key, value in data.items(): if ist((key, value)): ss += key print(f'this makes a valid pair {key}') print(f'Sum of all the keys is: {ss}') if __name__ == '__main__': main() can someone help
Advent of Code 2024 | Day 08 "Resonant Collinearity"
19:46
HyperNeutrino
Рет қаралды 3,1 М.
Advent of Code 2024 | Day 09 "Disk Fragmenter"
12:04
HyperNeutrino
Рет қаралды 3,7 М.
Хаги Ваги говорит разными голосами
0:22
Фани Хани
Рет қаралды 2,2 МЛН
요즘유행 찍는법
0:34
오마이비키 OMV
Рет қаралды 12 МЛН
Why YOU Should Do Advent of Code
4:34
Theo - t3․gg
Рет қаралды 37 М.
Advent of Code 2024 | Day 17 "Chronospatial Computer"
47:21
HyperNeutrino
Рет қаралды 5 М.
🎄 Advent of code 2024 in F# - day 07
6:56
Jo Van Eyck
Рет қаралды 199
Advent of Code 2024 | Day 13 "Claw Contraption"
16:43
HyperNeutrino
Рет қаралды 4 М.
Advent of Code 2024 | Day 10 "Hoof It"
15:54
HyperNeutrino
Рет қаралды 2,3 М.
day 07 - advent of code 2024 in rust
17:36
chris biscardi
Рет қаралды 2 М.
Advent of Code 2024 | Day 15 "Warehouse Woes"
27:35
HyperNeutrino
Рет қаралды 2,9 М.
Day 4 | Advent of Code 2024
9:18
Errichto Algorithms
Рет қаралды 4,3 М.
Advent of Code 2024 | Day 14 "Restroom Redoubt"
15:49
HyperNeutrino
Рет қаралды 3,3 М.