# competitive-programming

Competitive programming is a computing activity involving programming contests, courses, problem solving, and related educational practice.

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

## Saving Christmas with Kotlin

DevFeed: [Saving Christmas with Kotlin](<https://devfeed.tech/articles/saving-christmas-with-kotlin-24739.md>)

Original publisher: [Read original article](<https://medium.com/xorum-io/saving-christmas-with-kotlin-e3e239b6fe3d?source=rss----92bb7980cc9f---4>)

Author: Yev Kanivets

Published: 2022-01-29T12:24:13Z

Content type: tutorial

Language: en

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

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

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

### AI overview

A developer describes using Kotlin to complete all 50 challenges of Advent of Code 2021 over 25 days and shares links to a four-part series of Kotlin ideas and solutions. The article also discusses Kotlin's suitability for competitive programming.

### Source excerpt

It's been a month since I've saved a Christmas. Now, I feel it's time to tell you exactly how I did it. I wasn't alone, though. My faithful companion was crucial to the success of my mission. Yes, Kotlin, I'm talking about you. But let's return to the day when it all started: I was minding my own business on a ship at sea when the overboard alarm goes off! I rushed to see if I could help. Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying into the ocean!Before I knew it, I was inside a submarine the Elves kept ready for situations like this. It was covered in Christmas lights (because of course it is), and it even had an experimental antenna that should be able to track the keys if I could boost its signal strength high enough; there was a little meter that indicated the antenna's signal strength by displaying 0-50 stars.My instincts told me that in order to save Christmas, I needed to get all fifty stars by December 25th. It turns out that 200K+ other people happened to get into a similar situation. You can still see the complete log of our adventures on this site. Some people call it the "Advent of Code" and say it happens yearly. My way down It took me 25 days and 50 challenges (yeah, two challenges per day) to get those sleigh keys and save the Christmas. Every day at 7 a.m. (UTC+2), we reached a new milestone that unlocked two more challenges to solve. Most of them took from one to two hours to get done. Thank God there was a pretty good Internet connection in my submarine (I could even work remotely and didn't need to take a vacation for such a noble task), so I still had plenty of time to share my ideas and solutions: Ideas and Solutions for Advent of Code 2021 in Kotlin -- Part 1/4 Ideas and Solutions for Advent of Code 2021 in Kotlin -- Part 2/4 Ideas and Solutions for Advent of Code 2021 in Kotlin -- Part 3/4 Ideas and Solutions for Advent of Code 2021 in Kotlin -- Part 4/4 Spending 25 days locked in a submarine and solving chall

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

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

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

Author: Yev Kanivets

Published: 2021-12-26T14:22:49Z

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>), [Programming](<https://devfeed.tech/topics/programming.md>), [competitive-programming](<https://devfeed.tech/topics/competitive-programming.md>), [Graphs](<https://devfeed.tech/topics/graphs.md>), [math](<https://devfeed.tech/topics/math.md>)

Tags: [advent-of-code](<https://devfeed.tech/tags/advent-of-code.md>), [algorithms](<https://devfeed.tech/tags/algorithms.md>), [array](<https://devfeed.tech/tags/array.md>), [code](<https://devfeed.tech/tags/code.md>), [competitive-programming](<https://devfeed.tech/tags/competitive-programming.md>), [data-structures](<https://devfeed.tech/tags/data-structures.md>), [graph-theory](<https://devfeed.tech/tags/graph-theory.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [memory](<https://devfeed.tech/tags/memory.md>), [pairs](<https://devfeed.tech/tags/pairs.md>), [programming](<https://devfeed.tech/tags/programming.md>), [solutions](<https://devfeed.tech/tags/solutions.md>), [time](<https://devfeed.tech/tags/time.md>)

### AI overview

This article presents high-level ideas and Kotlin solutions for Advent of Code 2021 tasks from days 13 to 15. It discusses folding a 2D array, modeling polymer growth with dynamic programming, and finding a shortest path in a 2D array.

### Source excerpt

Ideas and Solutions for Advent of Code 2021 in Kotlin -- Part 3/4 The third week of Advent of Code requires more time and even some competitive programming knowledge like dynamic programming and graph theory. In this article, I share some high-level ideas and my solutions if you need a hint or a few to get that gold star. Ideas and Solutions for tasks 1 to 6 can be found here, for tasks 7 to 12 -- here. Day 13: Transparent Origami The 2D array contains two types of symbols -- . and #. This array can be folded horizontally and vertically multiple times. When folding # symbols replace . symbols, but not vice versa. Here is the complete task. This is a modeling task, which you can do on the 2D array itself, but the possible range is quite large, so you can hit a memory limit. The smarter solution would be to fold the # symbols (the initial input, actually). Such folding can be done with Kotlin's fold function using the initial value of # symbol positions and mapNotNull, which mirrors X or Y coordinates depending on the fold direction. Here is my solution. Day 14: Extended Polymerization We get the initial string (template) consisting of uppercase letters, which describe the initial state of the polymer. The list of pair insertion rules allows growing the initial polymer step by step exponentially. We need to model this growth during 10 (first sub-task) and 40 (second sub-task) steps. Here is the complete task. The first sub-task can be solved just by modeling, but even 20 steps are too long and require too much memory and time. The (much) better solution is based on dynamic programming. You can easily see that every pair grows independently of others (new elements are always added inside the pair). It means that the solution can be found for each pair separately and then combined. It doesn't speed up things sufficiently though. But makes the solution easier? Yes. Now, let's grow each pair step by step. So at each step, every pair (usually) produces two more pairs, which h