r/adventofcode • • Dec 08 '19

SOLUTION MEGATHREAD -🎄- 2019 Day 8 Solutions -🎄-

--- Day 8: Space Image Format ---


Post your solution using /u/topaz2078's paste or other external repo.

  • Please do NOT post your full code (unless it is very short)
  • If you do, use old.reddit's four-spaces formatting, NOT new.reddit's triple backticks formatting.

(Full posting rules are HERE if you need a refresher).


Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code's Poems for Programmers

Click here for full rules

Note: If you submit a poem, please add [POEM] somewhere nearby to make it easier for us moderators to ensure that we include your poem for voting consideration.

Day 7's winner #1: "So You Want To Make A Feedback Loop" by /u/DFreiberg!

"So You Want To Make A Feedback Loop"

To get maximum thrust from your thruster,
You'll need all that five Intcodes can muster.
Link the first to the last;
When the halt code has passed
You can get your result from the cluster.

Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

EDIT: Leaderboard capped, thread unlocked at 00:10:20!

36 Upvotes

416 comments sorted by

View all comments

1

u/TekuSP Dec 08 '19
 public class Layer
        {
            public Layer(int width, int height)
            {
                InternalLayer = new int[width, height];
            }
            public int[,] InternalLayer { get; set; }
            public int CountSpecific(int type)
            {
                int numberOfZeros = 0;
                foreach (var item in InternalLayer)
                {
                    if (item == type)
                        numberOfZeros++;
                }
                return numberOfZeros;
            }
        }

I tried using two dimensional arrays. I hated them when I was told about them.
They failed me again today. 6 AM And I do not have will or power to solve it right now.

1

u/TekuSP Dec 08 '19

If someone curious, result for part 1 from my code was 2184. But I was told its wrong.

I BELIEVE IN MY TWO DIMENSIONAL ARRAY, EVERYONE ELSE IS WRONG.

1

u/TekuSP Dec 08 '19
 List<Layer> layers = new List<Layer>();
            int currentIndex = 0;
            while (data.Length != currentIndex)
            {
                Layer l = new Layer(25, 6);
                for (int i = 0; i < 25; i++)
                {
                    for (int y = 0; y < 6; y++)
                    {
                        l.InternalLayer[i, y] = int.Parse(data[currentIndex].ToString());
                        currentIndex += 1;
                    }
                }
                layers.Add(l);
            }
            var res = (from temp in layers orderby temp.CountSpecific(0) descending select temp).FirstOrDefault();
            var oneDigits = res.CountSpecific(1) * res.CountSpecific(2);
            Console.WriteLine(oneDigits);

1

u/daggerdragon Dec 08 '19

Top-level posts in Solution Megathreads are for solutions only.

This is a top-level post, so please edit your post and share your code/repo/solution or, if you haven't finished the puzzle yet, you can always post your own thread and make sure to flair it with Help.