no time today but 6 part 1 started
This commit is contained in:
51
2019/6thDay/challenge.txt
Normal file
51
2019/6thDay/challenge.txt
Normal file
@@ -0,0 +1,51 @@
|
||||
--- Day 6: Universal Orbit Map ---
|
||||
You've landed at the Universal Orbit Map facility on Mercury. Because navigation in space often involves transferring between orbits, the orbit maps here are useful for finding efficient routes between, for example, you and Santa. You download a map of the local orbits (your puzzle input).
|
||||
|
||||
Except for the universal Center of Mass (COM), every object in space is in orbit around exactly one other object. An orbit looks roughly like this:
|
||||
|
||||
\
|
||||
\
|
||||
|
|
||||
|
|
||||
AAA--> o o <--BBB
|
||||
|
|
||||
|
|
||||
/
|
||||
/
|
||||
In this diagram, the object BBB is in orbit around AAA. The path that BBB takes around AAA (drawn with lines) is only partly shown. In the map data, this orbital relationship is written AAA)BBB, which means "BBB is in orbit around AAA".
|
||||
|
||||
Before you use your map data to plot a course, you need to make sure it wasn't corrupted during the download. To verify maps, the Universal Orbit Map facility uses orbit count checksums - the total number of direct orbits (like the one shown above) and indirect orbits.
|
||||
|
||||
Whenever A orbits B and B orbits C, then A indirectly orbits C. This chain can be any number of objects long: if A orbits B, B orbits C, and C orbits D, then A indirectly orbits D.
|
||||
|
||||
For example, suppose you have the following map:
|
||||
|
||||
COM)B
|
||||
B)C
|
||||
C)D
|
||||
D)E
|
||||
E)F
|
||||
B)G
|
||||
G)H
|
||||
D)I
|
||||
E)J
|
||||
J)K
|
||||
K)L
|
||||
Visually, the above map of orbits looks like this:
|
||||
|
||||
G - H J - K - L
|
||||
/ /
|
||||
COM - B - C - D - E - F
|
||||
\
|
||||
I
|
||||
In this visual representation, when two objects are connected by a line, the one on the right directly orbits the one on the left.
|
||||
|
||||
Here, we can count the total number of orbits as follows:
|
||||
|
||||
D directly orbits C and indirectly orbits B and COM, a total of 3 orbits.
|
||||
L directly orbits K and indirectly orbits J, E, D, C, B, and COM, a total of 7 orbits.
|
||||
COM orbits nothing.
|
||||
The total number of direct and indirect orbits in this example is 42.
|
||||
|
||||
What is the total number of direct and indirect orbits in your map data?
|
||||
|
||||
56
2019/6thDay/challenge1.cpp
Normal file
56
2019/6thDay/challenge1.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
|
||||
std::unordered_map<std::string, std::string> mapise( std::vector<std::string> input )
|
||||
{
|
||||
|
||||
std::unordered_map<std::string, std::string> ret;
|
||||
|
||||
for ( auto& str : input )
|
||||
{
|
||||
std::string first = str.substr(0, 3);
|
||||
std::string second = str.substr(4, str.size());
|
||||
|
||||
ret[first] = second;
|
||||
std::cout << first << " " << second << std::endl;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::ifstream infile( argv[1] );
|
||||
|
||||
std::vector<std::string> lines;
|
||||
|
||||
std::string line;
|
||||
while (!infile.eof())
|
||||
{
|
||||
|
||||
std::getline(infile, line);
|
||||
if ( line.length() == 0 ) continue;
|
||||
lines.push_back(line);
|
||||
|
||||
}
|
||||
|
||||
int accumilator = 0;
|
||||
|
||||
auto map = mapise( lines );
|
||||
|
||||
std::unordered_map<std::string, std::string>::iterator it;
|
||||
for (it = map.begin(); it != map.end(); it++)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::cout << "Sum of direct and indirect orbits : " << accumilator << std::endl;
|
||||
|
||||
}
|
||||
BIN
2019/6thDay/challenge1.exe
Normal file
BIN
2019/6thDay/challenge1.exe
Normal file
Binary file not shown.
1589
2019/6thDay/input.txt
Normal file
1589
2019/6thDay/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user