# codenewbie

Published articles for codenewbie.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Idiomatic Kotlin: Solving Advent of Code Puzzles, Binary Boarding

DevFeed: [Idiomatic Kotlin: Solving Advent of Code Puzzles, Binary Boarding](<https://devfeed.tech/articles/idiomatic-kotlin-solving-advent-of-code-puzzles-binary-boarding-22984.md>)

Original publisher: [Read original article](<https://dev.to/kotlin/idiomatic-kotlin-solving-advent-of-code-puzzles-binary-boarding-513e>)

Author: Svetlana Isakova

Published: 2021-09-10T08:50:58Z

Content type: tutorial

Language: en

Sources: [Kotlin](<https://devfeed.tech/sources/kotlin-2.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Advent of Code](<https://devfeed.tech/topics/advent-of-code.md>), [Code Challenge](<https://devfeed.tech/topics/code-challenge.md>), [Algorithm](<https://devfeed.tech/topics/algorithm.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [100daysofcode](<https://devfeed.tech/tags/100daysofcode.md>), [advent-of-code](<https://devfeed.tech/tags/advent-of-code.md>), [adventofcode](<https://devfeed.tech/tags/adventofcode.md>), [algorithm](<https://devfeed.tech/tags/algorithm.md>), [code](<https://devfeed.tech/tags/code.md>), [code-challenge](<https://devfeed.tech/tags/code-challenge.md>), [codenewbie](<https://devfeed.tech/tags/codenewbie.md>), [coding](<https://devfeed.tech/tags/coding.md>), [community](<https://devfeed.tech/tags/community.md>), [development](<https://devfeed.tech/tags/development.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [inclusive](<https://devfeed.tech/tags/inclusive.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [software](<https://devfeed.tech/tags/software.md>)

### AI overview

A Kotlin tutorial solves Advent of Code 2020 Day 5, Binary Boarding. It explains how boarding-pass characters encode rows and columns as binary values, then uses seat IDs to identify the highest seat ID and the missing seat.

### Source excerpt

Let's continue our journey of understanding what "idiomatic Kotlin" means and solve one more puzzle from the Advent of Code challenge. The puzzles are independent of each other, so you don't need to check any of the previous ones we've already covered. Simply read through the following solution or watch the video. We hope you learn something new! Day 5. Binary Boarding We're boarding the plane! We need to analyze the list of boarding passes and find the seat with the highest seat ID. Then we need to find the one seat missing from the list, which is ours. You can find the full task description at https://adventofcode.com/2020/day/5.* A seat is specified as, for example, FBFBBFFRLR, where F means "front", B means "back", L means "left", and R means "right". The first 7 characters are either F or B and they specify exactly one of the 128 rows on the plane (numbered 0 through 127). The last three characters are either L or R; these specify exactly one of the 8 columns of seats on the plane (numbered 0 through 7). A more detailed encoding description is given on the puzzle page. Every seat has a unique seat ID, calculated by multiplying the row by 8 and then adding the column. The puzzle input is the list of boarding passes. The first task is to find the boarding pass in this list with the highest seat ID. The second task is to find the missing boarding pass in the list. The flight is completely full, there's only one missing boarding pass, and that's our seat. However, some of the seats at the very front and back of the plane don't exist on this aircraft, so they are missing from the list as well. As usual, we suggest that you try to solve the task on your own before reading the solution. Here's how you can set up Kotlin for this purpose. Solution Let's first discuss the encoding of the boarding passes. Note how it is a nicely "hidden" binary representation of natural numbers! Let's take a closer look. Boarding pass: binary representation First, let's look at the rows.

## Idiomatic Kotlin: Solving Advent of Code Puzzles, Passport Validation

DevFeed: [Idiomatic Kotlin: Solving Advent of Code Puzzles, Passport Validation](<https://devfeed.tech/articles/idiomatic-kotlin-solving-advent-of-code-puzzles-passport-validation-22986.md>)

Original publisher: [Read original article](<https://dev.to/kotlin/idiomatic-kotlin-solving-advent-of-code-puzzles-passport-validation-1425>)

Author: Sebastian Aigner

Published: 2021-09-01T14:52:59Z

Content type: tutorial

Language: en

Sources: [Kotlin](<https://devfeed.tech/sources/kotlin-2.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Advent of Code](<https://devfeed.tech/topics/advent-of-code.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Sanitization](<https://devfeed.tech/topics/sanitization.md>)

Tags: [100daysofcode](<https://devfeed.tech/tags/100daysofcode.md>), [advent-of-code](<https://devfeed.tech/tags/advent-of-code.md>), [adventofcode](<https://devfeed.tech/tags/adventofcode.md>), [code](<https://devfeed.tech/tags/code.md>), [codenewbie](<https://devfeed.tech/tags/codenewbie.md>), [coding](<https://devfeed.tech/tags/coding.md>), [community](<https://devfeed.tech/tags/community.md>), [development](<https://devfeed.tech/tags/development.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [files](<https://devfeed.tech/tags/files.md>), [inclusive](<https://devfeed.tech/tags/inclusive.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [linux](<https://devfeed.tech/tags/linux.md>), [macos](<https://devfeed.tech/tags/macos.md>), [software](<https://devfeed.tech/tags/software.md>), [validation](<https://devfeed.tech/tags/validation.md>)

### AI overview

A tutorial on solving Advent of Code 2020 Day 4, Passport Processing, with Kotlin. It explains how to parse passport records separated by blank lines, extract key-value pairs, and count passports containing all required fields.

### Source excerpt

Today in "Idiomatic Kotlin", we're looking at day 4 of the Advent of Code 2020 challenges, in which we tackle a problem that feels as old as programming itself: input sanitization and validation. Day 4. Passport processing We need to build a passport scanner that, given a batch of input text, can count how many passports are valid. You can find the complete task description at https://adventofcode.com/2020/day/4. Like many challenges, we first inspect our input: ecl:gry pid:860033327 eyr:2020 hcl:#fffffd byr:1937 iyr:2017 cid:147 hgt:183cm iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884 hcl:#cfa07d byr:1929 hcl:#ae17e1 iyr:2013 eyr:2024 ecl:brn pid:760753108 byr:1931 hgt:179cm The input is a batch of travel documents in a text file, separated by blank lines. Each passport is represented as a sequence of key-colon-value pairs separated by spaces or newlines. Our challenge is finding out how many passports are valid. For part one, "valid" means that they need to have all the required fields outlined by the security personnel: byr, iyr, eyr, hgt, hcl, ecl and pid (we conveniently ignore their request to validate the cid field). Solving Day 4, Part 1 Like many challenges, we start by reading our puzzle input as text and trim off any extraneous whitespace at the beginning and the end of the file. As per the description, passports are always separated by blank lines. A blank line is just two "returns", or newlines, in a row, so we'll use this to split our input string into the individual passports: val passports = File("src/day04/input.txt") .readText() .trim() .split("\n\n", "\r\n\r\n") (Note that depending on your operating system, the line separator in text files is different: On Windows, it is \r\n, on Linux and macOS, it's \n. Kotlin's split method takes an arbitrary number of delimiters, allowing us to cover both cases directly.) We now have a list of passport strings. However, working with lists of raw strings can quickly get confusing. Let's use Kotlin's expressiv

## Idiomatic Kotlin: Solving Advent of Code Puzzles, Day 2

DevFeed: [Idiomatic Kotlin: Solving Advent of Code Puzzles, Day 2](<https://devfeed.tech/articles/idiomatic-kotlin-solving-advent-of-code-puzzles-day-2-22985.md>)

Original publisher: [Read original article](<https://dev.to/kotlin/idiomatic-kotlin-solving-advent-of-code-puzzles-day-2-pe2>)

Author: Svetlana Isakova

Published: 2021-07-21T16:25:30Z

Content type: tutorial

Language: en

Sources: [Kotlin](<https://devfeed.tech/sources/kotlin-2.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Advent of Code](<https://devfeed.tech/topics/advent-of-code.md>), [Code](<https://devfeed.tech/topics/code.md>), [passwords](<https://devfeed.tech/topics/passwords.md>)

Tags: [100daysofcode](<https://devfeed.tech/tags/100daysofcode.md>), [advent-of-code](<https://devfeed.tech/tags/advent-of-code.md>), [adventofcode](<https://devfeed.tech/tags/adventofcode.md>), [code](<https://devfeed.tech/tags/code.md>), [codenewbie](<https://devfeed.tech/tags/codenewbie.md>), [coding](<https://devfeed.tech/tags/coding.md>), [community](<https://devfeed.tech/tags/community.md>), [development](<https://devfeed.tech/tags/development.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [inclusive](<https://devfeed.tech/tags/inclusive.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [password](<https://devfeed.tech/tags/password.md>), [passwords](<https://devfeed.tech/tags/passwords.md>), [software](<https://devfeed.tech/tags/software.md>)

### AI overview

A tutorial on writing idiomatic Kotlin while solving Advent of Code 2020 Day 2. It explains the two password-policy interpretations: counting letter occurrences within a range, and requiring the letter in exactly one of two specified positions, then begins implementing input parsing and a Kotlin data class for the policy and password.

### Source excerpt

Idiomatic Kotlin: Solving Advent of Code Puzzles, Day 2 Let's continue learning how to write idiomatic Kotlin code by solving the AdventOfCode tasks! Today, we're discussing the solution for the day 2 task. Day 2. Password philosophy We need to confirm that passwords meet the corporate policy. Find the full task description at https://adventofcode.com/2020/day/2*. First, we need to read the input: 1-3 a: abcde 1-3 b: cdefg 2-9 c: ccccccccc Each line contains the password policy and the password. Our task is to check that the password is valid and conforms to the given policy. The policies are different in the first and the second parts of the task. In the first part, the password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid. For example, 1-3 a means that the password must contain a at least once and at most 3 times. In the example, two passwords, the first and the third ones, are valid. The first contains one a, and the third contains nine cs, both within the limits of their respective policies. The second password, cdefg, is invalid, as it contains no instances of b but needs at least 1. In the second part, the policy describes two positions in the password, where 1 means the first character, 2 means the second character, and so on (indexing starts at 1, not 0). Exactly one of these positions must contain the given letter. Other occurrences of the letter are irrelevant. Given the same example list from above: 1-3 a: abcde is valid: position 1 contains a and position 3 does not. 1-3 b: cdefg is invalid: neither position 1 nor position 3 contains b. 2-9 c: ccccccccc is invalid: both positions 2 and position 9 contain c. We should count the number of passwords from the given input that are valid according to the interpretations of the policies. As usual, if you haven't done it, please solve the task yourself first. Here's how you can set up Kotlin for this purpose. Solution First, we should read and pa

## Solving Advent of Code Puzzles in Idiomatic Kotlin

DevFeed: [Solving Advent of Code Puzzles in Idiomatic Kotlin](<https://devfeed.tech/articles/solving-advent-of-code-puzzles-in-idiomatic-kotlin-22987.md>)

Original publisher: [Read original article](<https://dev.to/kotlin/solving-advent-of-code-puzzles-in-idiomatic-kotlin-1m62>)

Author: Svetlana Isakova

Published: 2021-07-15T12:41:37Z

Content type: tutorial

Language: en

Sources: [Kotlin](<https://devfeed.tech/sources/kotlin-2.md>)

Topics: [Advent of Code](<https://devfeed.tech/topics/advent-of-code.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [IntelliJ IDEA](<https://devfeed.tech/topics/intellij-idea.md>)

Tags: [100daysofcode](<https://devfeed.tech/tags/100daysofcode.md>), [advent-of-code](<https://devfeed.tech/tags/advent-of-code.md>), [adventofcode](<https://devfeed.tech/tags/adventofcode.md>), [codenewbie](<https://devfeed.tech/tags/codenewbie.md>), [coding](<https://devfeed.tech/tags/coding.md>), [community](<https://devfeed.tech/tags/community.md>), [development](<https://devfeed.tech/tags/development.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [ide](<https://devfeed.tech/tags/ide.md>), [inclusive](<https://devfeed.tech/tags/inclusive.md>), [intellij-idea](<https://devfeed.tech/tags/intellij-idea.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [software](<https://devfeed.tech/tags/software.md>), [solutions](<https://devfeed.tech/tags/solutions.md>)

### AI overview

A tutorial introduces Advent of Code as a way to practice Kotlin and presents solutions for the 2020 challenges, beginning with Day 1's Report Repair task. It explains how to set up a Kotlin project, use IntelliJ IDEA or an online editor, and solve the task by finding two or three entries that sum to 2020.

### Source excerpt

What's the best way to learn a language other than writing some code with it? Solving fun and short tasks like the ones from Advent of Code might be a great opportunity to practice your language skills, and you can learn a lot if you compare your solutions with how others have solved the same problem. Lots of developers from around the world, including some from the Kotlin team, take part in the Advent of Code challenges created by Eric Wastl. Advent of Code is a series of tasks published every December, which you solve and compete with others. Many would agree that it's the best advent calendar to celebrate Christmas and New Year! To help the community learn idiomatic Kotlin, and motivate more developers to solve Advent of Code tasks in Kotlin in the future, we decided to prepare solutions for the tasks from Advent of Code 2020. It doesn't matter if you solved it back in December, you're ready to solve it now, or you just want to check the solutions - we hope you'll find something useful in these materials. Of course, it works best if you try to solve the same task first yourself! Below is the solution and video for the first task. If you find this format useful and want us to cover more tasks in a similar fashion, please share in the comments! Day 1. Report Repair We're fixing an expense report! Find the full task description at https://adventofcode.com/2020/day/1*. You need to find the two (and in the second part, three) entries from the list of numbers that sum to 2020 and then multiply those two (or three) numbers together. How to solve the task Register at https://adventofcode.com/, open the task at https://adventofcode.com/2020/day/1, write your solution in Kotlin, and check the result on the site. You can either write Kotlin code online or using an IDE: download the free Community Edition of IntelliJ IDEA create a Kotlin project write your solution there Finally, compare your solution with the solution below. We marked the src folder as a source set to put t