So are, 8, 9, 10 & 13. If ppl don't want to listen to those episodes that is totally fine
@anapaulamendozadiaz88906 күн бұрын
As a lambda lover, I fricking love this!
@sho65017 күн бұрын
Can you make more videos like this? really enjoyed it!
@ruffianeo34188 күн бұрын
Every language wants to be a Lisp and every Lisp wants to be a Common Lisp... truth hurts ;) CL-USER> (defparameter *data* '((1 2 3) (5 5 5) (3 1 4))) CL-USER> (loop for x in (mapcar #'(lambda (line) (reduce #'+ line :initial-value 0)) *data*) maximizing x) 15 Or if you like to read the flow of data left to right, with a little help of my usual utilities: CL-USER> (pipeline (x *data*) (mapcar #'(lambda (line) (reduce #'+ line :initial-value 0)) x) (reduce #'max x :initial-value 0)) 15 Or if you like loops because all that reduce and map stuff is so unsimple... CL-USER> (loop for line in *data* maximizing (loop for x in line summing x)) 15
@nikiiv10 күн бұрын
```Elixir Enum.min_max([20,30,22,25]) |> then(fn {min, max} -> Integer.gcd(min, max) end) ``` Skips going over twice for the min and then for the max
@nikiiv10 күн бұрын
I'd submit this Elixir solution ```Elixir [[1,2,3],[5,5,5],[5,6,7]] |> Enum.max_by(&Enum.sum/1) |> Enum.sum() ``` or ```Elixir [[1,2,3],[5,5,5],[5,6,7]] |> Enum.map(&Enum.sum/1) |> Enum.max ``` It is funny how max_by is almost what is needed but not exactly..
@G1171311 күн бұрын
Since the C++ code is the only definition of "calculate", it is not a bug. Consequently, the unguarded range in Rust while elegant is wrong.
@pha199412 күн бұрын
I guess what people initially start to do is compress songs which are the biggest and see if the size goes under the drive capacity. But if you do this based on the size of the biggest to smallest song then you *may* have to compress more songs than necessary. This is because it is possible for example that only two songs which provided "maximum amount of compression" was needed. But if you do it based on each song size, biggest to smallest song, you"may" end up with a higher count. So focus on compressing songs based on which ones provide the "maximum compression", which is basically what a-b represents, so as to minimize the number of songs that you need to compress.
@d69p-eix13 күн бұрын
If one prefers compact syntax, one could produce the same functionality in cpp with -v+1 where v is an array, and across all your projects data structures with operator overloading in the base class, syntax really has nothing to do with the ideas of category theory
@0LoneTech15 күн бұрын
I had this silly feeling it can't be necessary to write the scan twice. |(»+`){𝔽-𝔽⌾⌽} This was the first time I wanted a ⟜ variant of ⌾. Prior variants: {|-⟜⌽˝(»+`)˘≍⟜⌽𝕩} # both directions in one 2d array {|-⟜⌽○(»+`)⟜⌽˜𝕩} # ○ to scan both sides, but missing ⌾ And then there's the awfully assymetric reduce and scan variant: |(+´⊸--(»2×+`))
@Pylo90415 күн бұрын
*hits the head on keyboard while holding AltGr* “Extremely beautiful!”
@tomekk.188916 күн бұрын
Wow this is some horribly written code
@KnakuanaRka19 күн бұрын
TIL about that Counter and other stuff; that’s nice to know.
@davidzwitser23 күн бұрын
His setup and organization is so cool. Love the implementation and love the LSP update!
@christbaumerАй бұрын
`calculate = sum . filter even .* enumFromTo`
@whydoineedausername1386Ай бұрын
Honestly a bit disappointed. It might still be BQN, but I was hoping for an array style solution as I was struggling with my own APL solution to part 2. (Then I realised that I literally just had to change an or to a plus so that's good now)
@compsciwins-p4dАй бұрын
Love your video. Great stuff😊
@rupertwhАй бұрын
That 'bug' in C code seemed more like a design choice to me. But anyway, the real and much more sinister bug in the C version lies in the '<='! Think about what happens when top==INT_MAX.
@rubenvergАй бұрын
what I wanted to say yesterday is I think you can remove the whole ×≠next? part and always do each on next since when it's empty it stays empty, might be wrong though
@code_reportАй бұрын
You are correct again! 🙏 I have updated the code : ) and cleaned it up even more
@acquiteАй бұрын
what happened to day 8 and 9..?
@code_reportАй бұрын
I will probably make videos for them, just decided to may Day 10 out of order
@klipronhowardАй бұрын
I want to give BQN a try one day because i can't imagine myself ever being able to write code like this.
@misterpopo3736Ай бұрын
vscode has an extension, you don't have to type the symbols, just the name of it
@klipronhowardАй бұрын
Love your videos. I'm doing Advent of Code in Python and Javascript and I understand everything you are saying but none of your code. It's like I'm trying to read an Alien Language.
@code_reportАй бұрын
Thanks to @rubenverg and Rampoina for helped clean up my solution! 🙏 Meant to mention at the top of the video but forgot
@pmcgee003Ай бұрын
I had a bit of fun looking at the structure of the data. The book pages are basically nodes and the order rules are directed edges. So I wanted to pick a line of data, then restrict the rules down to just those nodes, and then look at the graph. I think it's interesting. See here at 4:20 and 6:20 (not BQN related). kzbin.info/www/bejne/qpyrkKN5Yr96fbM
@pmcgee003Ай бұрын
Really? Really?? "That's a rotate"? Is there no getting away from this? 😀
@GanerrrАй бұрын
id love to stick my solutions in my own lang in the comments but youtube constantly eats them
@bzboiiАй бұрын
1:45 actually -90 deg turn
@gigog27Ай бұрын
Rewatching some old videos, I think this is a pretty nice point-free solution in bqn. ×´⊸÷ It's also 4 characters, but instead of an identity it uses bqn's "before". This is a more bqn-way to do it, and it even allows it to be placed in an expression without parentheses: ×´⊸÷ n However, the apl-style solution with identity still works in bqn, but the parentheses are needed: (×´÷⊢) n
@rubenvergАй бұрын
I was really surprirsed when I saw people doing pure brute force like this and it actually ran in reasonable time
@foresthobo1166Ай бұрын
Still 2-3 orders of magnitude slower than the reverse algorithms. And that is for n in the teens.
@speedstyle.Ай бұрын
'beautiful' superquadratic solutions... it could be O(n)...
@aly-bocarcisse613Ай бұрын
Can someone explain the delta trick to compute the new direction ? I did not get it.😊
@code_reportАй бұрын
You always make a right turn. So dx is a list of 4 x y deltas of the offsets to move your position either up, right, ,down or left (in that order). Dir (direction) is used to index into that, and whenever you need to make a turn you just +1 to dir (and also mod 4 to reset to 0).
@krccmsitp2884Ай бұрын
Well, BQN looks... interesting... ;-)
@GermanLcАй бұрын
thats cheating
@toomuchdeeznutАй бұрын
For part 2, instead of testing with every non wall position, I test with only every position from the path I get from part 1, because if the additional wall is not on the original path, the guard won't hit the wall and change path anyway (I didn't use BQN but I did with Rust iterator)
@kevinmarques9334Ай бұрын
I didn't quite understand your counter approach to check if the guard's path is in a loop... I figured that the obstacle only makes any difference if it's placed in the guard's path, so for each position in the guard's path I put a obstacle and recalculate the new route. My solution to check if an array of positions is in a loop I separated the last two positions and compared if it appeared in the tail of the list. It was a nightmare in JavaScript, but after some tries (3-5 min each) I managed to solve it
@relaciboАй бұрын
I think, because a loop will run infinitly, the counter will be greater then the array size eventually. It's just very inefficient. I suspect the bqn solution, as elegant as it might be, will not run in any reasonable amount of time with the "real" problem input. Also because of the missed optimization opportunity, that you mentioned. Even in rust it took ~20-30 seconds for me.
@batlinАй бұрын
I stored each new (x,y,dir) triple in a set so a loop is discovered when the next state is already in the set. Together with the other optimisation you mentioned, only placing obstacles along the path generated in part 1, made it faster but still a bit slow in Picat (maybe 30s).
@aly-bocarcisse613Ай бұрын
@@batlinyou just replied to my question on direction, thanks
@TankorSmashАй бұрын
My BQN solution does something like this, where it calculates the previous tiles, and then goes through each one and adds an obstacle there and checks for tiles the guard has already been on. It takes like 3 minutes to run through the final solution though. Not nearly as elegant by a long shot
@kedarshinde4216Ай бұрын
Every day I think, surely today's problem can't be solved in BQN, every day I am proven wrong
Ай бұрын
It's turing complete.
@Denny_ZmeenАй бұрын
I feel like you could use table (⌜) to simplify this last expression, no ? +´⥊∾(⌽∘⍉⍟(↕4)m)Xm⌜ 3‿3↕𝕩
@aly-bocarcisse613Ай бұрын
I really enjoy your content in general but you literally converted me into array programing 😂. I’ll get started on this next year for sure. Can someone point me to the minute where it is checked that we have at most three digits ?
@code_reportАй бұрын
You don't need to check that. Many solutions do but it is unnecessary.
@MegaPacoquinhaАй бұрын
How long do you take on average to solve a AoC problem in bqn?
@code_reportАй бұрын
Day 1 and 2 were both less <10 minutes. Day 3 was around 20 minutes I believe. Day 4 and 5 closer to an hour (was exploring different solutions). Day 6 (just A) was over an hour as my recursive solution stack overflowed - had to switch to a •_while_
@MegaPacoquinhaАй бұрын
@code_report awesome, sometimes I get stuck for long in a question and I wonder how long does it take for others
@TankorSmashАй бұрын
@@MegaPacoquinha It took me, a newbie to BQN, 8 hours for part 3, 5ish for part 4 and just 1.5 hours for part 5. I haven't uploaded any of them past the first ones yet, but it sounds like we're in the same boat in terms of going _real_ slow. I hope we both keep at it!
@stefano8936Ай бұрын
well if you say that 3.33 is more readable than the for loop I don't need to see further
@zin_the_oneАй бұрын
Been using this AoC as an opportunity to learn BQN. Didn't know about that pattern where all ordered pairs make an upper triangle. I spent 2 hours on implementing selection sort making things way more complicated xD Min ← (⊑∘(((∊⟜rules)˜⋈)◶⟨⌽,⊢⟩∘⋈)) sorted ← (⌽∾)∘(((((∊⟜(⋈Min´)˜)⊸⊔)∘⊑)∾(1⊸↓))⍟(≠∾))∘⋈¨updates sol ← (+´⊑∘((⌊(÷⟜2)∘≠)⊏⊢)¨)¨updates((≢¨)⊔⊢)sorted
@rubenvergАй бұрын
oh, I should clarify I stole the grade down table self thing from bqncrate, so it's presumably by Marshall! not my idea(:
@DanielAjoyАй бұрын
these two are equivalent: 0⌈ 1⌊ ¯2‿¯1‿0‿1‿2 0< ¯2‿¯1‿0‿1‿2
@davidzwitserАй бұрын
Super cool 😁 fun to see how differently this can be approached. I was also inspired by dzaima's solution, I have a video of mine on my channel if that's interesting
@swedishpsychopath8795Ай бұрын
What is the point of constanly having to compare rust to other languages? Can't it stand on its own legs and be a tool in the tool box as the other languages for us to pick up when we need exactly that ONE feature that attrackts you the most? Does it have to be just one swiss-army language in the tool-box? If so I prefer plain old ANSI-C (and java for OOP).
@aly-bocarcisse613Ай бұрын
Seriously, this is great ?
@jakubgaecki5629Ай бұрын
Alternative (simpler?) solution to checking the X pattern in part 2: extract the diagonals into a 2x3 matrix, laminate it with its reverse, then check if exactly 2 rows are equal to 'MAS'.
@nunzioturtulici9636Ай бұрын
As regards the safe function one can avoid doing the two checks 1≤x≤3 doing |x-2|≤1, in APL: (∧/(1≥∘|2-|)∧(1=≢∘∪∘×))(2-/⊢)
@boredstudent9468Ай бұрын
Where can I find more about that diagonals function, while not bqn I tried solving it declaratively but the diagonals broke me.
@code_reportАй бұрын
Just wrote this up, hope it helps: mlochbaum.github.io/BQN/try.html#code=TG9nIOKGkCB74oCiU2hvdyDwnZWo4oC/8J2VqX0KCiJtIiBMb2cgbSDihpAgM+KAvzPipYrihpU5CkQg4oaQICgr4oycwrTihpXCqOKImOKJoiniirjiipQKCiMgU3RlcCBieSBTdGVwCiJyYW5nZSBvZiBlYWNoIGRpbWVuc3Rpb24iIExvZyDihpXCqOKJoiBtCiJvdXRlciBwcm9kIHN1bSIgTG9nICgr4oycwrTihpXCqOKImOKJoiltCiJncm91cCIg4oC/ICgoK+KMnMK04oaVwqjiiJjiiaIp4oq44oqUIG0p
@joepike1972Ай бұрын
I am just in my voyage of using APL where all of this was supper valuable. I had watched it before when the value went way over my head.