GithubHelp home page GithubHelp logo

vss2sn / advent_of_code Goto Github PK

View Code? Open in Web Editor NEW
43.0 4.0 9.0 557 KB

This repository contains solutions to each of the problems in Advent of Code 2017, 2018, 2019, 2020, 2021, 2022 and 2023 in C++ (and 2020 in Python as well)

C++ 92.27% Python 7.73%
aoc cpp advent-of-code advent-of-code-2020 adventofcode advent-of-code-2019 aoc-2021 aoc-2021-cpp aoc-2021-in-cpp advent-of-code-2021

advent_of_code's People

Contributors

vss2sn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

advent_of_code's Issues

Code review request for AOC 2022 Day 3

I have been using your repo to see solutions to days for AOC when I am stuck. Unfortunately I have no skill at C++ and cannot understand your day 3 part 1 code. I just wanted to ask - can you tell me why this code is showing me a value 2 thirds of the value that I get when I run your day 3 code with my input? My answer is incorrect but my code seems correct (even with the example problem they gave in the website). Am I missing something? Could you please help me?

#include "..\aoc.h"

void Day3Part1()
{
  std::vector<std::string> input = read_file("C:\\Users\\sanja\\OneDrive\\Documents\\Coding\\GitHubProjects\\AdventOfCode-Stuffs\\2022\\aoc\\C++\\day-3\\input.txt");
  int answer = 0;
  int lineSize = 0;
  int counter = 1;
  int times = 1;

  bool found = false;

  std::vector<char> half = std::vector<char>();
  std::vector<char> oldHalf = std::vector<char>();

  std::map<char, int> priorities = std::map<char, int>();
  priorities = { {'a', 1}, {'b', 2}, {'c', 3}, {'d', 4}, {'e', 5}, {'f', 6}, {'g', 7}, {'h', 8}, {'i', 9}, {'j', 10}, {'k', 11}, {'l', 12}, {'m', 13}, {'n', 14}, {'o', 15}, {'p', 16}, {'q', 17}, {'r', 18}, {'s', 19}, {'t', 20}, {'u', 21}, {'v', 22}, {'w', 23}, {'x', 24}, {'y', 25}, {'z', 26}, {'A', 27}, {'B', 28}, {'C', 29}, {'D', 30}, {'E', 31}, {'F', 31}, {'G', 33}, {'H', 34}, {'I', 35}, {'J', 36}, {'K', 37}, {'L', 38}, {'M', 39}, {'N', 40}, {'O', 41}, {'P', 42}, {'Q', 43}, {'R', 44}, {'S', 45}, {'T', 46}, {'U', 47}, {'V', 48}, {'W', 49}, {'X', 50}, {'Y', 51}, {'Z', 52} };

  for (std::string l : input)
  {
    lineSize = l.size();
    for (char c : l)
    {
      half.push_back(c);
      if (counter == lineSize / 2)
      {
        oldHalf = half;
        half.clear();
      }
      else if (counter == lineSize)
      {
        for (char h : half)
        {
          for (char o : oldHalf)
          {
            if (h == o)
            {
              //std::cout << "Size: " << lineSize << "\nCounter: " << counter << "\nH and O: " << h << " and " << o << "\nTIMES " << times << std::endl;
              answer += priorities[o];
              //std::cout << "ANSWER " << answer << std::endl;
              found = true;
              times++;
              break;
            }
          }
          if (found)
          {
            break;
          }
        }
      }
      counter++;
    }
    counter = 1;
    half.clear();
    oldHalf.clear();
    found = false;
  }

  std::cout << "The answer is " << answer << std::endl;
}

int main()
{
  Day3Part1();
  return 0;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.