vss2sn / advent_of_code Goto Github PK
View Code? Open in Web Editor NEWThis 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)
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)
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;
}
The variable name prev_position on line 39 in day14*.cpp
This file does not calculate all the scores on the 9th day of 2017.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.