Learn Kotlin with the Kotlin Team: Advent of Code 2020 #4

preview_player
Показать описание
We continue to Learn Kotlin with the Kotlin team! In the fourth episode of Advent of Code 2020 series, you will be tackling input sanitization and validation challenges. This video will help you to Learn idiomatic Kotlin.

Input sanitization and validation feels like a problem as old as programming itself. User input can’t always be trusted, and ensuring it takes the exact form that we, as programmers expect, can take serious brain power. Stick around for the challenge and an elegant solution. Learn Kotlin to tackle this problem easily.

Advent of Code 2020 Day 4: Passport processing
Apply the 'when' expression and explore different ways of how to validate the input: utility functions, working with ranges, checking set membership, and matching a particular regular expression.

0:50 Problem description
1:23 Solving part I
4:57 Solving part II
12:18 Wrapping up

* Used with the permission of Advent of Code (Eric Wastl)
#Kotlin #Idiomatic #Tutorial #AdventOfCode #AdventOfCode2020 #AdventOfСodeInKotlin #Day4
Рекомендации по теме
Комментарии
Автор

Thats kotlin for you. Concise, expressive and elegant.

vengateshm
Автор

A great video, Seb. It is hard to imaging how much work it takes to make it so smooth.

noraltavir
Автор

Pls put a "Day 4" in the Title, so it can be found better ;)

Amejonah
Автор

These are absolutely excellent - and you're a very charismatic presenter! Love all of this content, please keep it coming!

codeluggage
Автор

Solve more Advent of Code and I will continue my subscription ;)

LeAstrale
Автор

Всем салют! Ребята, спасибо за науку!

andrey
Автор

It's an okay-ish solution. I'd prefer to either use a passport data class which has defined type-safe fields (which would lend itself nicely to bean validation), OR have a class "PassportField" with a generic for the value type, a "name" field and a "validate(value)" method. The latter is more suitable than defined fields if the fields change a lot. Using a map is quick-and-dirty but gives you the worst of both worlds - not being type safe while also forcing you to do "when(key)" in all relevant places.

AlanDarkworld
Автор

To be honest instead of complex "when" I would make "requiredFields" a map of key to lambda of validation method, then it would be even simpler

buszi_
Автор

Just curious, what are the pros/cons of using more regex validation? Challenge 1 could be solved using a regex. For Challenge 2, the eye color, passport, and hair color (as used in the video) could all be done with regex matching.

blinkmacalahan