Advent of Code 2021 in Kotlin, Day 1: Sonar Sweep

preview_player
Показать описание


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

Thanks for sharing, being new to Kotlin I didn't know about windowed and went with forEach loops.

Can't wait to see day 2 and maybe some more unknown Kotlin features.

Ent_rush
Автор

Loved the 2020 videos you did and am loving these 2021 videos. It's so neat to compare this to how I'd do it in Python or Ruby and see where different languages are easier or harder. Can't wait to see the next few videos that are in my queue.

EricMesa
Автор

there is also a zipWithNext function which is similar to windowed(2) but generates list elements of type Pair instead of List. I also made use of the transformer argument of window function in second part to convert the window from list of 3 elements to its sum, and then fed it all back to function in part one which counts the increases. This approach is not as optimized as the code in the video however i think it reads more like english.
Also the same operations can be done on sequences which is really cool and scalable!

Phlyrox
Автор

Ohh I didn't know you could destructure a list into variables like this! Thanks!

outadoc
Автор

love the standard kotlin library 💕💕💕💕💕💕❤❤

droid-aman
Автор

Or perhaps even more readable: it.first() < it.last() instead of it[0] < it[3]

MrRillard
Автор

The entire operation is done in 1 single line... neat and efficient.
And strange... when i try my version of code then answer is passed by the puzzle but when i try the code mentioned here i get completely different answer.
Also using following in part 2 shows Type Mismatch

(a, b) -> a.sum() < b.sum()
}

soodssr
Автор

Could someone explain why he chose window of 4 instead of 3?

zeusalmighty
Автор

Haha, my solution looks very dumb in comparison

jt_hopp