CHEEEEEEEEEEEESE

‘Cheesewheel’. Good name! But why C#?
cheesewheel/cheesewheel-day01-1.cs
cheesewheel/cheesewheel-day01-1.cs
using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Assignment_1 {
        class Program {
            static void Main(string[] args) {
                int increaseCounter = 0;
                int same = 0;
                int currentMes = 0;
                int lastMes = 0;
    
                foreach (string line in System.IO.File.ReadLines("../../input.txt")) {
                    currentMes = int.Parse(line);
                    string output = currentMes.ToString();
    
                    if (lastMes == 0) {
                        output += " (N/A - no previous measurement)";
                    }
                    else {
                        if (lastMes < currentMes) {
                            increaseCounter++;
                            output += " (increased)";
                        }
                        else {
                            if (lastMes > currentMes) {
                                output += " (decreased)";
                            }
                            else {
                                same++;
                            }
                            
                        }
                    }
    
                    Console.WriteLine(output);
                    lastMes = currentMes;
                }
    
                Console.WriteLine("Total amount measurement increased: " + increaseCounter + ". Total amount it stayed the same: " + same);
                Console.ReadLine();
    
            }
        }
    }
    
cheesewheel/cheesewheel-day01-2.cs
cheesewheel/cheesewheel-day01-2.cs
using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Assignment_2 {
        class Program {
            static void Main(string[] args) {
                List<int> measureList = new List<int>();
                int currentSum = 0;
                int lastSum = 0;
                int increaseCounter = 0;
    
                foreach (string line in System.IO.File.ReadLines("../../input.txt")) {
                    measureList.Add(int.Parse(line));
                }
    
                for (int i = 0; (i+2) < measureList.Count(); i++) {
                    currentSum = measureList[i] + measureList[i+1] + measureList[i+2];
                    string output = currentSum.ToString();
    
                    if (lastSum == 0) {
                        output += " (N/A - no previous measurement)";
                    }
                    else {
                        if (currentSum > lastSum) {
                            increaseCounter++;
                            output += " (increased)";
                        }
                        else {
                            if (currentSum < lastSum) {
                                output += " (decreased)";
                            }
                            else {
                                output += " (no change)";
                            }
                        }
                    }
    
                    lastSum = currentSum;
                    Console.WriteLine(output);
                }
    
                Console.WriteLine("Total amount measurement increased: " + increaseCounter);
                Console.ReadLine();
            }
        }
    }
    
cheesewheel/day02-1.cs
cheesewheel/day02-1.cs
using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Assignment_1 {
        class Program {
            static void Main(string[] args) {
                int horPos = 0;
                int verPos = 0;
                int movement;
                char action;
                string[] lineSplit;
    
                foreach (string line in System.IO.File.ReadLines("../../input.txt")) {
                    action = line[0];
                    lineSplit = line.Split(' ');
                    movement = int.Parse(lineSplit[1]);
    
                    switch (action) {
                        case 'd':    
                            verPos += movement;
                            Console.WriteLine("The submarine went down {0} units", movement);
                            break;
    
                        case 'f':
                            horPos += movement;
                            Console.WriteLine("The submarine went forward {0} units", movement);
                            break;
    
                        case 'u':
                            verPos -= movement;
                            Console.WriteLine("The submarine went up {0} units", movement);
                            break;
    
                    }
                }
    
                Console.WriteLine("The submarine ends at a depth of {0} units and a horizontal position of {1} units", verPos, horPos);
                Console.WriteLine("Multiplying them gives {0}", verPos \* horPos);
                Console.ReadLine();
            }
        }
    }
    
cheesewheel/day02-2.cs
cheesewheel/day02-2.cs
using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Assignment_2 {
        class Program {
            static void Main(string[] args) {
                int horPos = 0;
                int verPos = 0;
                int aim = 0;
                int movement;
                char action;
                string[] lineSplit;
    
                foreach (string line in System.IO.File.ReadLines("../../input.txt")) {
                    action = line[0];
                    lineSplit = line.Split(' ');
                    movement = int.Parse(lineSplit[1]);
    
                    switch (action) {
                        case 'd':
                            aim += movement;
                            Console.WriteLine("The submarine adjusted the aim down with {0} units, it is now {1}", movement, aim);
                            break;
    
                        case 'f':
                            horPos += movement;
                            verPos += movement \* aim;
                            Console.WriteLine("The submarine moved {0} units with an aim of {1}, reaches a depth of {2}", movement, aim, verPos);
                            break;
    
                        case 'u':
                            aim -= movement;
                            Console.WriteLine("The submarine adjusted the aim up with {0} units, it is now {1}", movement, aim);
                            break;
                    }
                }
                Console.WriteLine("Answer: {0}", horPos \* verPos);
                Console.ReadLine();
            }
        }
    }
    

Tags: