<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wen Jun</title>
    <description>The latest articles on DEV Community by Wen Jun (@xlzior).</description>
    <link>https://dev.to/xlzior</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F745972%2F7cdb0327-5a0e-496a-bafa-6f31d755b1f2.png</url>
      <title>DEV Community: Wen Jun</title>
      <link>https://dev.to/xlzior</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/xlzior"/>
    <language>en</language>
    <item>
      <title>Telegram Games: An Intermediate Guide</title>
      <dc:creator>Wen Jun</dc:creator>
      <pubDate>Mon, 01 Aug 2022 06:07:57 +0000</pubDate>
      <link>https://dev.to/xlzior/telegram-games-an-intermediate-guide-45io</link>
      <guid>https://dev.to/xlzior/telegram-games-an-intermediate-guide-45io</guid>
      <description>&lt;p&gt;I recently created a game on Telegram. This was not my first Telegram bot, but it would be my first game. Hence, I first checked the official Telegram &lt;a href="https://core.telegram.org/bots/games" rel="noopener noreferrer"&gt;documentation for their gaming platform&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4830opk886flalnvvbw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4830opk886flalnvvbw.png" alt="Telegram Gaming Platform documentation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While reading it, I felt it was rather skimpy on the details. I also wished they would link to the &lt;a href="https://core.telegram.org/bots/api" rel="noopener noreferrer"&gt;bot API documentation&lt;/a&gt; directly, so that I could see the exact objects, methods and fields involved.&lt;/p&gt;

&lt;p&gt;This guide is meant to provide slightly more details (and useful links) than the existing documentation, but is not meant to be a step-by-step guide. It is language-agnostic so that you can apply these concepts regardless of which language you choose to write your bot and game in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Game
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create a Telegram Bot using &lt;code&gt;/newbot&lt;/code&gt; on &lt;a href="https://t.me/BotFather" rel="noopener noreferrer"&gt;@BotFather&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Enable inline mode for the bot using &lt;code&gt;/setinline&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a new game using &lt;code&gt;/newgame&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After this process, you will have your bot token and your &lt;code&gt;game_short_name&lt;/code&gt;, which will be used later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Launching the Game
&lt;/h2&gt;

&lt;p&gt;Here's what the documentation says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Once the game is created, your bot can send it to chats as regular messages, or offer them via inline mode.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's break that down.&lt;/p&gt;

&lt;p&gt;It may help to read about &lt;a href="https://core.telegram.org/bots/inline" rel="noopener noreferrer"&gt;inline mode&lt;/a&gt; and &lt;a href="https://core.telegram.org/bots/2-0-intro#callback-buttons" rel="noopener noreferrer"&gt;callback buttons&lt;/a&gt; first.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sending games to chats as regular messages
&lt;/h3&gt;

&lt;p&gt;For example, you could have the bot respond to the &lt;code&gt;/start&lt;/code&gt; command (or any other command/phrase of your choice) by sending the game.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ljpajcpe3o5maj7k24a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ljpajcpe3o5maj7k24a.png" alt="User sends /start, bot responds with game"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's a sequence diagram for what goes on behind the scenes. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fogumg4cgn7ze3uulrdkv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fogumg4cgn7ze3uulrdkv.png" alt="Sequence diagram for sending games to chats as regular messages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user initiates the conversation with your chosen phrase&lt;/li&gt;
&lt;li&gt;Your bot will receive a &lt;a href="https://core.telegram.org/bots/api#message" rel="noopener noreferrer"&gt;Message&lt;/a&gt; object containing the message that was sent&lt;/li&gt;
&lt;li&gt;You may respond using the &lt;a href="https://core.telegram.org/bots/api#sendgame" rel="noopener noreferrer"&gt;&lt;code&gt;sendGame&lt;/code&gt;&lt;/a&gt; API, which is fairly straightforward as the only required fields are &lt;code&gt;chat_id&lt;/code&gt; and &lt;code&gt;game_short_name&lt;/code&gt; (from the set up process)&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;bot&lt;/strong&gt; sends a message with the game and a "Play &lt;em&gt;Game Name&lt;/em&gt;" callback button&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Next, the callback interactions occur.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user clicks on "Play &lt;em&gt;Game Name&lt;/em&gt;"&lt;/li&gt;
&lt;li&gt;Telegram sends a &lt;a href="https://core.telegram.org/bots/api#callbackquery" rel="noopener noreferrer"&gt;&lt;code&gt;CallbackQuery&lt;/code&gt;&lt;/a&gt; with &lt;code&gt;game_short_name&lt;/code&gt; to your bot&lt;/li&gt;
&lt;li&gt;Your bot calls &lt;a href="https://core.telegram.org/bots/api#callbackquery" rel="noopener noreferrer"&gt;&lt;code&gt;answerCallbackQuery&lt;/code&gt;&lt;/a&gt; with a url to the game&lt;/li&gt;
&lt;li&gt;Telegram opens the url to the game&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Offering games via inline mode
&lt;/h2&gt;

&lt;p&gt;This was the part that confused me the most.&lt;/p&gt;

&lt;p&gt;Here is the equivalent sequence diagram for the interactions between the user, Telegram and your bot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0rziogzx1l9ocvvzyo91.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0rziogzx1l9ocvvzyo91.png" alt="Sequence diagram for offering games via inline mode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user initiates the interaction by typing "&lt;em&gt;@your_bot_username&lt;/em&gt;" in any chat&lt;/li&gt;
&lt;li&gt;Telegram sends an &lt;a href="https://core.telegram.org/bots/api#inlinequery" rel="noopener noreferrer"&gt;&lt;code&gt;InlineQuery&lt;/code&gt;&lt;/a&gt; to your bot&lt;/li&gt;
&lt;li&gt;Your bot calls &lt;a href="https://core.telegram.org/bots/api#answerinlinequery" rel="noopener noreferrer"&gt;&lt;code&gt;answerInlineQuery&lt;/code&gt;&lt;/a&gt; with an array of &lt;a href="https://core.telegram.org/bots/api#inlinequeryresultgame" rel="noopener noreferrer"&gt;&lt;code&gt;InlineQueryResultGame&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Telegram displays the results to the user &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdm08s3brau5e1pl36l3o.png" alt="Telegram displays the results to the user"&gt;
&lt;/li&gt;
&lt;li&gt;The user selects a game from the list&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;user&lt;/strong&gt; sends a message (via your bot) the game and a "Play &lt;em&gt;Game Name&lt;/em&gt;" callback button. &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4vhef4j62vz82a6gsviy.png" alt="User sends a message with the game"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The remaining flow for launching the game via callback interactions is the same as before.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This guide provides more elaboration on the interactions between the user, Telegram and your bot when launching a game.&lt;/p&gt;

&lt;p&gt;An interesting difference between these two methods is that in the first, the bot is the one who sends the message containing the game. In the second, the user who initiated the inline query is the one who sends the game. This is because the bot may not be a part of the group chat (as it is an inline interaction).&lt;/p&gt;

&lt;p&gt;Hope this guide helped you, and happy coding!&lt;/p&gt;

</description>
      <category>telegram</category>
      <category>bot</category>
      <category>telegrambot</category>
      <category>game</category>
    </item>
    <item>
      <title>What I learnt from Advent of Code 2021</title>
      <dc:creator>Wen Jun</dc:creator>
      <pubDate>Sun, 26 Dec 2021 03:30:20 +0000</pubDate>
      <link>https://dev.to/xlzior/what-i-learnt-from-advent-of-code-2021-1c6a</link>
      <guid>https://dev.to/xlzior/what-i-learnt-from-advent-of-code-2021-1c6a</guid>
      <description>&lt;p&gt;&lt;a href="https://adventofcode.com/"&gt;Advent of Code&lt;/a&gt; (AoC) is a yearly coding challenge in the form of an &lt;a href="https://en.wikipedia.org/wiki/Advent_calendar"&gt;Advent calendar&lt;/a&gt;. Every day from Dec 1 to 25, a small programming puzzle is released and &lt;a href="https://adventofcode.com/2021/stats"&gt;hundreds of thousands&lt;/a&gt; of people attempt to solve the problems.&lt;/p&gt;

&lt;p&gt;As this year’s Advent of Code comes to a close, I wanted to reflect on my AoC journey thus far.&lt;/p&gt;




&lt;p&gt;I first attempted AoC in 2018. However, I was somewhat “under levelled” back then, as I did not have much experience in object-oriented programming or data structures and algorithms. Since then, I have accumulated much more experience and taken modules that helped refine my computational thinking and hone my programming skills. As a result, I was much better equipped to tackle the challenges this year and managed to achieve all 50 stars by Christmas.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9_VfXAYr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3ci6789gig3ofn8ouy1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9_VfXAYr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3ci6789gig3ofn8ouy1.png" alt="Advent of Code Calendar" width="880" height="629"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Technical aspects
&lt;/h3&gt;

&lt;p&gt;I found that the difficulty level of this year’s puzzles scaled somewhat linearly, which made for a very enjoyable experience. My friend and I remarked that "the difficulty creeps up on you, and you only realise how far you’ve come when you look back at your solutions from a week ago, or even a few days ago". From &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2015/Day15-2.py"&gt;Dijkstra’s&lt;/a&gt; &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2023/Day23-2.py"&gt;algorithm&lt;/a&gt; to the &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2022/Day22-2.py"&gt;Inclusion-Exclusion Principle&lt;/a&gt;, I was certainly challenged technically.&lt;/p&gt;

&lt;p&gt;For a more detailed rundown of notable problems, check out my other article: &lt;a href="https://dev.to/xlzior/notable-problems-from-advent-of-code/2021-2lp9"&gt;Notable problems from Advent of Code 2021&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Non-technical aspects
&lt;/h3&gt;

&lt;p&gt;I found that I learned more in terms of non-technical aspects than technical ones.&lt;/p&gt;

&lt;h4&gt;
  
  
  It’s all about the community
&lt;/h4&gt;

&lt;p&gt;My sister told me that her biggest mistake in university was “trying to do it alone”. I tend to be an individualist, but her advice resonated with me during this year’s AoC. &lt;/p&gt;

&lt;p&gt;During the pandemic, I found it harder to feel a sense of belonging and it was something I craved. For example, I missed the feeling of being physically in the same room as my classmates at school.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ebUAqmcI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f0mvyzaw2yp4kv8u29ir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ebUAqmcI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f0mvyzaw2yp4kv8u29ir.png" alt="Advent of Code subreddit" width="880" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After solving each problem, I would reward myself by visiting the &lt;a href="https://www.reddit.com/r/adventofcode"&gt;AoC subreddit&lt;/a&gt; in search of memes, cool visualisations and other people’s solutions. Reading about everyone’s experience and approaches to the problems contributed greatly to me feeling like I belonged to a community of like-minded people.&lt;/p&gt;

&lt;p&gt;It also helped that I had friends who were also participating in AoC. After we had independently solved the day’s problem, we would discuss and compare our approaches and code. &lt;/p&gt;

&lt;h4&gt;
  
  
  Dealing with imposter syndrome / fixed mindset
&lt;/h4&gt;

&lt;p&gt;One issue I remember having in 2018 was imposter syndrome / having a fixed mindset. I’d struggle through the problems with my limited knowledge of data structures and algorithms, and then I’d come across a solution that was far cleverer or more efficient than mine. My response to this would be to berate myself with “Ah dang, why didn’t I think of that?”, when a more reasonable response would have been “I still have lots to learn. What principles can I pick up from this solution so that I may come up with something like this in future?”.&lt;/p&gt;

&lt;p&gt;This year, I was able to come up with better solutions, although they were not the fastest, nor the shortest or the most elegant. Moreover, I was better able to deal with imposter syndrome and could switch to a growth mindset more easily, which is a testament to my personal growth since then. As a result, I could read about what others had done and learn from them.&lt;/p&gt;

&lt;h4&gt;
  
  
  Know your purpose
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SclelzFy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8sh7z24b6mlt004x7oib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SclelzFy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8sh7z24b6mlt004x7oib.png" alt="Do it for her meme" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AoC is many different things to different people. Some do it to learn a new language, or just to practice. Others take a more competitive route and make use of features like the global leaderboard or the private leaderboard.&lt;/p&gt;

&lt;p&gt;Although I had not decided what &lt;em&gt;my&lt;/em&gt; purpose was when I first started AoC, I did eventually distil out a few points through some soul-searching during the last week.&lt;/p&gt;

&lt;p&gt;I’m doing it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For myself&lt;/li&gt;
&lt;li&gt;For fun&lt;/li&gt;
&lt;li&gt;To practise object-oriented principles&lt;/li&gt;
&lt;li&gt;To practise writing good quality code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Equally importantly, I’m &lt;strong&gt;not&lt;/strong&gt; doing it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For the leaderboard&lt;/li&gt;
&lt;li&gt;To get the &lt;em&gt;fastest&lt;/em&gt; solution&lt;/li&gt;
&lt;li&gt;To get the &lt;em&gt;shortest&lt;/em&gt; solution&lt;/li&gt;
&lt;li&gt;To compete with my friends&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These principles guided my behaviour; I focused on writing clear, concise code that communicated the computational processes well.&lt;/p&gt;

&lt;p&gt;In particular, “for fun” allowed me to make better decisions about when it was time to get some help. I did this on two occasions.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://adventofcode.com/2021/day/22"&gt;Day 22: Reactor Reboot&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;My approach for this day involved implementing functions based on the &lt;a href="https://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle"&gt;Inclusion-Exclusion Principle&lt;/a&gt;. After spending 3 hours implementing it, I realised a fundamental flaw in my algorithm. I suspected that my approach of using the inclusion-exclusion principle was not wrong, but I could not figure out how to fix or work around the flaw. I eventually checked the Reddit megathread and found someone who had used a similar approach. From that solution, I was able to understand the proper way to apply the principle to the problem. To make sure that I fully understood their solution, I &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2022/Day22-2.py"&gt;re-implemented the algorithm&lt;/a&gt; without referring to their solution and was able to solve the problem.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://adventofcode.com/2021/day/24"&gt;Day 24: Arithmetic Logic Unit&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;This was a bizarre problem. I had re-implemented the ALU as the instructions seemed to imply I was supposed to but was faced with the prospect of having to brute force 9&lt;sup&gt;14&lt;/sup&gt; possible values. I tried reading the instructions in the puzzle input and running them by hand, but gave up after a few lines as I didn’t think it would lead me anywhere. This was my first time feeling completely lost on where to begin tackling a problem.&lt;/p&gt;

&lt;p&gt;I was distinctly not having fun, and rather than continue bashing my head at the problem, I decided I could justify turning to Reddit for a hint. The first small hint did not help much, at which point I dived into the solutions megathread. This was a good move as it turned out that this problem required a great deal of reverse engineering, far more than I was expecting. I did eventually repeat the steps of reverse engineering on my own and write &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2024/Day24.py"&gt;a script&lt;/a&gt; to solve the problem, just to prove to myself that I did understand it. I learned from other Reddit users that most years have at least one problem that requires reverse-engineering the puzzle input, so perhaps I will be better prepared next year, with this knowledge.&lt;/p&gt;

&lt;p&gt;Beyond a certain point, the chances of me coming up with a solution on my own become rather slim. Turning to Reddit for help on these two days allowed me to keep AoC a fun experience (which was my purpose), rather than a painfully mind-bending one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Closing Remarks
&lt;/h3&gt;

&lt;p&gt;A month ago, I never would have thought I would finish all 25 days of AoC, (mostly) unscathed, and I’m very happy to have made it this far.&lt;/p&gt;

&lt;p&gt;I am incredibly grateful to &lt;a href="http://was.tl/"&gt;Eric&lt;/a&gt; for putting in the effort to create such a fantastic challenge for the AoC community every year. I learned a lot from the past month and, most importantly, had lots of fun while doing it. I will miss jumping out of bed in the morning to refactor my previous day’s code. Perhaps next year, I’ll attempt AoC 2022 using a new language (Clojure? Go? C?) / library (NumPy) I’ve always wanted to try or get better at.&lt;/p&gt;

&lt;p&gt;That being said, I am glad it’s over. I could start to feel myself getting burnt out towards the end as I spent up to 6 hours a day stuck on the same problem. I look forward to a good break from AoC over the next few days.&lt;/p&gt;

</description>
      <category>adventofcode</category>
    </item>
    <item>
      <title>Notable problems from Advent of Code 2021</title>
      <dc:creator>Wen Jun</dc:creator>
      <pubDate>Sun, 26 Dec 2021 03:26:21 +0000</pubDate>
      <link>https://dev.to/xlzior/notable-problems-from-advent-of-code-2021-2lp9</link>
      <guid>https://dev.to/xlzior/notable-problems-from-advent-of-code-2021-2lp9</guid>
      <description>&lt;p&gt;&lt;a href="https://adventofcode.com/"&gt;Advent of Code&lt;/a&gt; (AoC) is a yearly coding challenge in the form of an &lt;a href="https://en.wikipedia.org/wiki/Advent_calendar"&gt;Advent calendar&lt;/a&gt;. Every day from Dec 1 to 25, a small programming puzzle is released and &lt;a href="https://adventofcode.com/2021/stats"&gt;hundreds of thousands&lt;/a&gt; of people attempt to solve the problems.&lt;/p&gt;

&lt;p&gt;As this year’s Advent of Code comes to a close, I wanted to reflect on my AoC journey thus far.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cUmQjSJ5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u6brjm8jfwcpvpjkelo5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cUmQjSJ5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u6brjm8jfwcpvpjkelo5.png" alt="Advent of Code Calendar" width="880" height="629"&gt;&lt;/a&gt; &lt;/p&gt;




&lt;p&gt;These are some of the notable problems from this year.&lt;/p&gt;

&lt;h2&gt;
  
  
  (Top favourite) &lt;a href="https://adventofcode.com/2021/day/16"&gt;Day 16: Packet Decoder&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This was by far my favourite problem. Although &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2016/Day16_next.py"&gt;my solution&lt;/a&gt; was not the shortest, I used object-oriented principles/features like inheritance and abstract classes and was very pleased with how my abstractions turned out. I’ve heard that the &lt;a href="https://esolangs.org/wiki/Intcode"&gt;2019 Intcode&lt;/a&gt; problems were similar to this and I’m excited to work on them next!&lt;/p&gt;

&lt;h2&gt;
  
  
  (Most enlightening) &lt;a href="https://adventofcode.com/2021/day/6"&gt;Day 6: Lanternfish&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This problem involved simulating a bunch of fish that would spawn new fish every 7 days. Like many others, &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%206/Day6_brute.py"&gt;my first instinct&lt;/a&gt; was to treat each Lanternfish as an individual entity (e.g. as a Python object) and iterate through an array of individual fish to spawn new fish. This worked fine for part 1 but not for part 2, which involved simulating more than 10&lt;sup&gt;12&lt;/sup&gt; fish.&lt;/p&gt;

&lt;p&gt;This was clearly not feasible and I was forced to try a &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%206/Day6.py"&gt;new approach&lt;/a&gt;. I realised that each &lt;em&gt;individual&lt;/em&gt; fish was not important and that I could group the fish based on the number of days until they next spawn a new fish. Hence, the only relevant piece of information was how many fish there were in each group. I was glad that I had arrived at this realisation all on my own, which made for a far more memorable learning experience compared to if someone had told me the trick directly.&lt;/p&gt;

&lt;p&gt;This concept (stop trying to deal with things as individuals, group them and keep track of only the relevant aggregated information) seemed to be a recurring theme and it came in useful for &lt;em&gt;&lt;strong&gt;&lt;a href="https://adventofcode.com/2021/day/14"&gt;Day 14: Extended Polymerisation&lt;/a&gt;&lt;/strong&gt; (&lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2014/Day14-3.py"&gt;my solution&lt;/a&gt;)&lt;/em&gt; and &lt;em&gt;&lt;strong&gt;&lt;a href="https://adventofcode.com/2021/day/21"&gt;Day 21: Dirac Dice&lt;/a&gt;&lt;/strong&gt; (&lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2021/Day21-2.py"&gt;my solution&lt;/a&gt;)&lt;/em&gt;. To this day, I remember this strategy as the “Lanternfish optimisation”.&lt;/p&gt;

&lt;p&gt;Later, I discussed my solution with two other friends who were also doing AoC and we realised that we had each come up with a different solution to the problem. We had a blast &lt;del&gt;arguing about fish&lt;/del&gt; explaining our solutions to each other and we learned a lot from the discussion.&lt;/p&gt;

&lt;h2&gt;
  
  
  (Most interesting) &lt;a href="https://adventofcode.com/2021/day/8"&gt;Day 8: Seven Segment Search&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This problem involved spotting patterns in the given problem statement and devising an algorithm that could eliminate possibilities, finally narrowing down to the last one. This was not particularly difficult, but there were many different ways to approach the problem. Some methods were more complicated and painful to code than others, while others were simpler and more elegant. I was not particularly pleased with my &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%208/Day8-2.py"&gt;first solution&lt;/a&gt;, so I picked a cool algorithm on Reddit and &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%208/Day8_redo.py"&gt;re-implemented it from scratch&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;My main takeaway from this day was to identify the best/simplest algorithm on paper first, before starting to code. Perhaps if I had taken more time to look for the simplest pattern, I would have been able to come up with a simpler and more elegant solution on my own.&lt;/p&gt;

&lt;h2&gt;
  
  
  (Most interesting) &lt;a href="https://adventofcode.com/2021/day/23"&gt;Day 23: Amphipod&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;One challenge I had solving this problem was figuring out how to represent the problem in terms of code. I eventually treated it as a standard &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2023/Day23-2.py"&gt;shortest path graph problem&lt;/a&gt; to be solved using Dijkstra’s. What was unique to this problem was the way of generating neighbours, which was highly visual and involved generating possible next states given a current state.&lt;/p&gt;

&lt;h2&gt;
  
  
  (Most challenging) &lt;a href="https://adventofcode.com/2021/day/19"&gt;Day 19: Beacon Scanner&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;I did not particularly enjoy this one, but I’m glad I ploughed through and &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2019/Day19-1.py"&gt;finished it&lt;/a&gt;. I did learn a lot from having to wrestle with the complexity of the problem. There are still optimisations I could make to my solution, but I’m in no rush to relive this day…&lt;/p&gt;

&lt;h2&gt;
  
  
  (Most satisfying) &lt;a href="https://adventofcode.com/2021/day/13"&gt;Day 13: Transparent Origami&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This problem involved simulating folding a piece of paper with dots on it and printing the final output. This was not computationally difficult, but it made the list because the answer was extremely satisfying, in a visual way. It felt incredible to run &lt;a href="https://github.com/xlzior/advent-of-code/blob/main/2021/Day%2013/Day13.py"&gt;my program&lt;/a&gt; on the puzzle input and have it print out the letters very clearly in the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uqMyesgQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yvz613mnpll7nnrqozg9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uqMyesgQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yvz613mnpll7nnrqozg9.png" alt="Day 13: Transparent Origami Solution" width="880" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>adventofcode</category>
      <category>python</category>
    </item>
  </channel>
</rss>
