AdventOfCode2021 - Day 7

This is a thread to discuss Day7
https://adventofcode.com/2021/day/7

REMEMBER!
It is VERY important NOT to write any public spoilers :slight_smile:
ALWAYS keep spoiler stuff hidden inside one of these

Summary

This text will be hidden

which you can obtain by clicking on the gear icon

image

The first iteration, quick&dirty, no optimisation at all, 'brute force'

Part1, 2 s

AoC.7 script pic

Part2, 17 s

Project

Part 1 done - 4.2 secs
Part 2 - 86 secs
Project

project

part 1 : 20 sec
part 2 : a very bad time ! even if I use HOF

part 2

image

@dardoro :i need some explications (if you have time): can you describe your algo plz.

questions inside Dardoro...
  1. why 0 in front
  2. what's this
    3)and at the last line : numbers from 0 to max shoud be min to max ? (what if you have a neg pos? or if position are between 100000-110000?) it will be much faster with min (i think!)
Brief responses

image

  1. why 0 in front
  2. what's this
    3)and at the last line : numbers from 0 to max shoud be min to max ? (what if you have a neg pos? or if position are between 100000-110000?) it will be much faster with min (i think!)

ad.1. It's initial value of the accumulator for combine. For the first iteration of combine, two first elements are used at once but EVERY element of the list must be processed by the expression
untitled script pic (6)
untitled script pic (7)
untitled script pic (8)

ad.2.Fuel consumption for distance of 4 = 1+2+3+4 i.e. $$\displaystyle\sum_{i=1}^ni = n(n+1)/2$$
ad.3 YES.
Values pretends to be a depth so rather >0 (there is no info about flying crabs or submarine :wink: ).
"min" will be probably faster if depth values doesn't cover whole (0..max) range. But "min" also takes some time...

Thank you !
i will try this in my project, i understand now why it's so faster than mine.

image = 5000 operations
ā€‹i=n(n+1)/2 = 1 operation