Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5639

Teaching and learning resources • Re: Advent of Code 2023

$
0
0
Cool! It's amazing what one can do functional style programming.

I'm having trouble with day 12. I think the main difficult is the decision to use Julia for every week. In previous years it was

The other difficulty with day 12 is that I peeked at Roman's solution at

https://github.com/elizarov/AdventOfCod ... Day12_1.kt

and can't think of anything other than a recursive search to solve it.
Okay, I'm done - for now. It's still too slow, but at least the result is accepted.
On opi5+

Code:

hrvoje@hrvoje64:~/Projects/advent-of-code/day12$ ./springs-1 cpu time: 9784 real time: 9788 gc time: 14797916
9.8 seconds :(
This is a brute force approach (my usual go-to, when I don't know what else to do).
Every line of code (first test line ???.### 1,1,3) is converted to
record string where (. W) (? Q) (# B), that is not to mess with regex special characters,
and 1,1,3 contiguous record is converted to regexp.
Then I find all positions of Qs (?) in the record string, and run combinations on them.
And there is the problem, say string with 10 Qs results in a list of 1024 possible arrangements for Qs. Then original string is mapped to all possible substitutions patterns, and is then filtered with the regexp. Those that remain are then counted.

Statistics: Posted by hrvoje064 — Wed Jan 10, 2024 4:58 am



Viewing all articles
Browse latest Browse all 5639

Trending Articles