# competetive-programming

Published articles for competetive-programming.

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

## Ideas and Solutions for Advent of Code 2021 in Kotlin -- Part 2/4

DevFeed: [Ideas and Solutions for Advent of Code 2021 in Kotlin -- Part 2/4](<https://devfeed.tech/articles/ideas-and-solutions-for-advent-of-code-2021-in-kotlin-part-2-4-24734.md>)

Original publisher: [Read original article](<https://medium.com/xorum-io/ideas-and-solutions-for-advent-of-code-2021-in-kotlin-part-2-4-5079d5066653?source=rss----92bb7980cc9f---4>)

Author: Yev Kanivets

Published: 2021-12-18T19:56:15Z

Content type: tutorial

Language: en

Sources: [xorum.io - Medium](<https://devfeed.tech/sources/xorum-io-medium.md>)

Topics: [Advent of Code](<https://devfeed.tech/topics/advent-of-code.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Algorithms, Complexity](<https://devfeed.tech/topics/algorithms-complexity.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>), [Graphs](<https://devfeed.tech/topics/graphs.md>)

Tags: [advent-of-code](<https://devfeed.tech/tags/advent-of-code.md>), [algorithms](<https://devfeed.tech/tags/algorithms.md>), [algorithms-and-data-structures](<https://devfeed.tech/tags/algorithms-and-data-structures.md>), [competetive-programming](<https://devfeed.tech/tags/competetive-programming.md>), [data-structures](<https://devfeed.tech/tags/data-structures.md>), [graph](<https://devfeed.tech/tags/graph.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>)

### AI overview

This article presents ideas and partial solutions for Advent of Code 2021 tasks 7 through 9 in Kotlin. It discusses minimizing alignment cost for an array, decoding malfunctioning seven-segment displays, and locating low points and basins in a two-dimensional digit map using breadth-first or depth-first search.

### Source excerpt

Ideas and Solutions for Advent of Code 2021 in Kotlin -- Part 2/4 The second week of Advent of Code introduces us to more difficult tasks, some of which require fundamental knowledge in algorithms and data structures. Do you need an idea or a tiny hint to get that gold star? Here we are, the second six tasks. What's special about this article? I won't be sharing the complete editorial, but the key idea only, so you can still solve the task by yourself. And if you need more guidance, there is a source code linked. Ideas and Solutions for tasks 1 to 6 can be found here. Day 7: The Treachery of Whales We are provided with an array of different values, which we need to align to a single value with the lowest possible cost. The cost function is different for the two sub-tasks. Here is the complete task. The solution is as simple as checking all possible values to align from min value to max value in the original array and choosing one with the lowest cost. The cost function (array of cost of moving value by 0, 1, 2 ... N) can be passed as an argument to your solution. Here is my solution. Day 8: Seven Segment Search Malfunctioning seven-segment digital display sends us some signals, which we need to decode knowing the representation of the full set of digits and which segments are used for each entry. Here is the complete task. The first sub-task requires you to parse only four digits -- 1, 4, 7, 8. All of them are unique in terms of segments used, so guessing them is relatively simple. The second sub-task asks you to guess the other 6 digits. I'm sure there are many different sequences in which you can guess them, but in my case, I've done the following: segments b and d are present in digit 4, but not in digit 1 segment bd is present only in digit 5 between all digits that use 5 segments then we can decode segments c and f by looking on the intersection of digits 1 and 5 using newly discovered segments, we find digits 3, 2, and 6 segment d can be found as an intersection o