19

Manipulating lists using windowed, scan, firstNotNullOfOrNull: Solving Advent of...

 3 years ago
source link: https://www.youtube.com/watch?v=vj3J9MuF1mI
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
#AdventOfCode #Kotlin #AdventOfСodeInKotlin

Manipulating lists using windowed, scan, firstNotNullOfOrNull: Solving Advent of Code Puzzles

1,390 views
Oct 13, 2021

In this episode of Idiomatic Kotlin’s #AdventOfCode series, we’ll look at different ways to manipulate lists in Kotlin to solve the puzzle. We’ll work with the ‘any’, ‘firstOrNull’, ‘firstNotNullOfOrNull’, ‘windowed’, ‘takeIf’, and ‘scan’ functions, which exemplify an idiomatic Kotlin style.

0:00 Intro 0:36 Puzzle Description 1:57 Solution, Part I 4:25 Finding invalid number 6:32 Using ‘windowed’ 9:08 Part II 9:52 Solution, Part II

Note about the difference between sublist and windowed functions → https://blog.jetbrains.com/kotlin/202... GitHub project → https://github.com/Kotlin-hands-on/ad... Blog post → https://blog.jetbrains.com/kotlin/202...

* Used with the permission of Advent of Code (Eric Wastl)

Idiomatic Kotlin: Solving Advent of Code Puzzles Series https://youtube.com/playlist?list=PLl...

#Kotlin #AdventOfСodeInKotlin #DAY9 #Idiomatic #Tutorial #AdventOfCode

Show lessShow more

11 Comments

Sort by
default-user=s48-c-k-c0x00ffffff-no-rj
Add a public comment...
windowed() is a really neat function. I've found it particularly useful in algorithms that deal with a "current" and a "previous" element in the list. It is much clearer and less error prone than fiddling with the indices manually and carefully working around all corner cases.

5 days ago

perhaps we could immediately break the inner loop, when the 'subListSum' is greater than the 'targetSum', to avoid unnecessary calculations for the rest 'toIndex'es, right?

4 days ago

Nice and neat solution, especially the improvement method of the second task, reminds of "integral image" from the viola jones face detection algorithm

5 days ago

There are some functions in this video that I need to check out.

3 days ago

I dont like the approach in the first function. It has twice the checks than if you were to check each element against only the ones following it.

5 days ago

??Kotlin multiplateform mobile Beginners tutorial upload

1 day ago


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK