🎄 Advent of code 2024 in F# - day 07

  Рет қаралды 202

Jo Van Eyck

Jo Van Eyck

Күн бұрын

Пікірлер: 1
@matthewjackson9288
@matthewjackson9288 Ай бұрын
I got pretty good time processing the list forward using binary recursion (or I guess ternary for part 2) at 0.15s for part2. At each step you can check if the sum or the product would be greater than the target and stop checking down that branch. However, it seems processing backwards allows for pruning the branches better. Glad I checked your video out. (code example is below in read more) let isEquationSatisfiableWithConcat (lhs, calibrations) = let rec loop runningTotal calibrations = match calibrations with | [] -> runningTotal = lhs | c :: remainingCalibrations -> let runningTotalProduct = runningTotal * c let runningTotalSum = runningTotal + c let runningTotalConcat = concat runningTotal c let productSatisfies = if runningTotalProduct > lhs then false else loop runningTotalProduct remainingCalibrations let sumSatisfies = if runningTotalSum > lhs || productSatisfies then false else loop runningTotalSum remainingCalibrations let concatSatisfies = if runningTotalConcat > lhs || productSatisfies || sumSatisfies then false else loop runningTotalConcat remainingCalibrations productSatisfies || sumSatisfies || concatSatisfies match calibrations with | c :: cs -> loop c cs | _ -> failwith "Expected at least one calibration component"
🎄 Advent of code 2024 in F# - day 01
18:25
Jo Van Eyck
Рет қаралды 639
day 01 - advent of code 2024
17:14
chris biscardi
Рет қаралды 14 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
i dove down the 7z rabbit hole (it goes deep)
12:50
Low Level
Рет қаралды 654 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 326 М.
I made Tetris in C, this is what I learned
15:15
Austin Larsen
Рет қаралды 31 М.
The Rust Survival Guide
12:34
Let's Get Rusty
Рет қаралды 180 М.
Day 2 | Advent of Code 2024 | Better Time Complexity
15:14
Errichto Algorithms
Рет қаралды 12 М.
🎄 Advent of code 2024 in F# - day 02
26:50
Jo Van Eyck
Рет қаралды 583
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 291 М.
Advent of Neovim: Why Neovim?
10:21
TJ DeVries
Рет қаралды 60 М.
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 107 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН