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

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

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

Author: Yev Kanivets

Published: 2021-12-13T15:31:55Z

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>), [Code](<https://devfeed.tech/topics/code.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>), [commands](<https://devfeed.tech/tags/commands.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>), [map](<https://devfeed.tech/tags/map.md>), [programming](<https://devfeed.tech/tags/programming.md>), [solutions](<https://devfeed.tech/tags/solutions.md>)

## AI overview

A Kotlin-focused walkthrough of the first six Advent of Code 2021 puzzles. It explains the key solution ideas for the early tasks, including array comparisons, submarine movement modeling, and binary-number calculations, while linking to source code for further guidance.

## Source excerpt

Ideas and Solutions for Advent of Code 2021 in Kotlin -- Part 1/4 There are so many things to do before Christmas, so I was always wondering how people find extra time to solve a daily programming puzzle of Advent of Code. Well, this year I'm one of those lucky folks with a bunch of spare time. Advent of Code is an annual event of Christmas-oriented programming challenges started December 2015. Every year since then, on the first day of December, a programming puzzle is published every day for twenty-four days. You can solve the puzzle and provide an answer using the language of your choice. Extra reason by JetBrains in the form of the giveaway of some Kotlin care packages has certainly contributed to my motivation. But what's the point of solving tasks without sharing your ideas and solutions with the community ;) So here we are, the first 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. Day 1: Sonar Sweep We are given an array of heights of a seafloor. We need to calculate the number of times heights (sub-task one) and sliding triples of heights (sub-task two) are increasing. Complete task is here. To solve both tasks we need to go from left to right and compare the previous element (or sliding triple) to the current one. That's pretty simple, but challenge yourself to craft the beautiful code. In Kotlin we may consider using drop and foldIndexed functions for this. Here is my solution. Day 2: Dive! The submarine can move in 2D space (horizontal position and depth) controlled by the set of commands. Moves mechanics are slightly different between subtasks, but the overall approach and goal are the same -- model moves and find the resulting position. Complete task is here. The first sub-task can be solved by folding horizontal position and depth changes, but the second sub-task should be modeled exact