Advent of Code 2021 in APL #1!

preview_player
Показать описание
In this video I cover the solution to Problem A & B from Day 1 of Advent of Code 2021.

Chapters:
0:00 Intro
0:53 Problem A Description
1:25 Problem A Solution
4:23 Problem B Description
4:48 Problem B Solution
7:00 Outro

Рекомендации по теме
Комментарии
Автор

Fun fact - you don't need to do the summing for part2 at all. Reasoning:
Call input list `x`, the list of sums `y`. Then `y_i = x_i + x_{i+1} + x_{i+2}`. We are looking for such `i`, that `y_i < y_{i+1}`, but substituting we get:
x_i + x_{i + 1} + x_{i+2} < x_{i+1} + x_{i+2} + x_{i+3}
and reducing:
x_i < x_{i+3}

Which in most functional languages leads to way nicer solutions (I am not sure if in APL it is true as this solution is simple on its own).

hashedone
Автор

Hey! Your videos made me fell in love with APL, i am totally at the beginning of my journey and wanted to attempt the AoC puzzles this year as well, but found it hard to find a tutorial on how to load the data from the puzzles into RIDE. I would greatly appreciate a short video where you go over how you did it ... :) Anyways, thanks for your videos, they give me great joy!

xcvh
Автор

This is the first I've seen of n-wise reductions; they made for a much nicer solution than I was able to come up with! I'll second Patrick's request for a short video on loading input data if that's alright with you. And thanks for the great content as always :)

TheEnderLeader
Автор

I've got literally the same solutions, very short and neat tacits!
Also thanks for infecting me with love for APL :D

PatrickStritch
Автор

Just wanted you to know I'm going to learn APL, just because of this video of yours. Also, someday I might have to talk to aliens so might as well get ready.

avisekhon
Автор

Total APL noob here. My first solution was a fork with a 1 rotate and dropped the last element. Watched the video and now I know about n wise reductions, thanks!

theamazingsolt
Автор

Really helpful video. The use of n-wise reductions was instructive. My 1st instinct was to look for such a solution but couldn't find the APL treatment. My solution was based on (1 rotate)-Identity.

rdatta
Автор

Interesting. I have absolutely no idea what trains are, but I got the gist of what's going on. I'm still not sure how I feel about languages with operators like APL. When you know what you're looking at, it's not so hard to read, but when you see something full of operators you're not familiar with it looks completely inscrutable. I've run into the same problem with Haskell from time to time. Named functions do have the benefit of... Having a name which hopefully helps you understand what it's doing.

I suppose that's mostly an issue for anyone who hasn't yet learned the language. But compared to something like COBOL, even if I can't write COBOL I've got a much better chance of being able to read it without knowing the language.

Bobbias
Автор

I took almost the same way with python using list comprehension... Thanks for the video

PietroBrunetti
Автор

As someone who has been trying to do this year's problems functionally but in Rust, the inefficiency of part two is erking me.

For part two I used Vec::windows to get the adjacent elements and then Iter::zip-ed it with itself but after Iter::skip-ing one element and then passing it through a filter where I compared the sums of two windows.

What's annoying me is that we're summing up the elements over and over again. I mean solving this imperatively, the most efficient solution is probably maintaining a rolling sum. Doing this functionally the only thing I can think of is maintaining an Iter::scan alongside another one element Iter::scan and subtracting the two.

Is there any better way to do the "rolling sum" implementation functionally in your opinion?

architbhonsle
Автор

I'm sure you probably knew already but you can print out the parse trees by doing ]box on -style=min -trains=tree -fns=on
Then you just input the function without any data and the parse tree will be printed out.

Dtgr
Автор

Do you think APL can be used like Perl for texto Pattern matching and data extration (mainly equipment config filés) with equivalent effort?

alessandrolima
Автор

Nice! Can you also show some free-point haskell solutions?

KicoWolf
Автор

Is this how they used to code in Ancient Greece or Ancient Egypt?

Actually, please do more videos. I love your explanations.

ShivanS