generated from sigonasr2/CPlusPlusProjectTemplate
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.9 KiB
84 lines
2.9 KiB
#define OLC_PGE_APPLICATION
|
|
#include "pixelGameEngine.h"
|
|
#include "olcutils.h"
|
|
#include <cassert>
|
|
|
|
using namespace olc;
|
|
|
|
int main()
|
|
{
|
|
std::map<std::string,bool>blocks;
|
|
std::ifstream file("testinput");
|
|
int minX=0,maxX=0,minY=0,maxY=0,minZ=0,maxZ=0;
|
|
int surfaceArea=0;
|
|
while (file.good()){
|
|
std::string line;
|
|
std::getline(file,line);
|
|
if (line.length()>0){
|
|
//std::cout<<line<<std::endl;
|
|
int marker=0;
|
|
int x=std::atoi(line.substr(marker,line.find(',',marker)-marker).c_str());
|
|
marker=line.find(',',marker)+1;
|
|
int y=std::atoi(line.substr(marker,line.find(',',marker)-marker).c_str());
|
|
marker=line.find(',',marker)+1;
|
|
int z=std::atoi(line.substr(marker,line.find(',',marker)-marker).c_str());
|
|
std::cout<<x<<","<<y<<","<<z<<std::endl;
|
|
minX=std::min(x,minX);
|
|
maxX=std::max(x,maxX);
|
|
minY=std::min(y,maxY);
|
|
maxY=std::max(y,maxY);
|
|
minZ=std::min(z,maxZ);
|
|
maxZ=std::max(z,maxZ);
|
|
if (blocks.find(std::to_string(x)+"_"+std::to_string(y-1)+"_"+std::to_string(z))==blocks.end()){
|
|
surfaceArea++;
|
|
} else {
|
|
surfaceArea--;
|
|
}
|
|
if (blocks.find(std::to_string(x)+"_"+std::to_string(y+1)+"_"+std::to_string(z))==blocks.end()){
|
|
surfaceArea++;
|
|
} else {
|
|
surfaceArea--;
|
|
}
|
|
if (blocks.find(std::to_string(x-1)+"_"+std::to_string(y)+"_"+std::to_string(z))==blocks.end()){
|
|
surfaceArea++;
|
|
} else {
|
|
surfaceArea--;
|
|
}
|
|
if (blocks.find(std::to_string(x+1)+"_"+std::to_string(y)+"_"+std::to_string(z))==blocks.end()){
|
|
surfaceArea++;
|
|
} else {
|
|
surfaceArea--;
|
|
}
|
|
if (blocks.find(std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z-1))==blocks.end()){
|
|
surfaceArea++;
|
|
} else {
|
|
surfaceArea--;
|
|
}
|
|
if (blocks.find(std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z+1))==blocks.end()){
|
|
surfaceArea++;
|
|
} else {
|
|
surfaceArea--;
|
|
}
|
|
if (blocks.find(std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z))==blocks.end()){
|
|
blocks[std::to_string(x)+"_"+std::to_string(y)+"_"+std::to_string(z)]=true;
|
|
} else {
|
|
std::cout<<"DUPLICATE FOUND!"<<std::endl;
|
|
assert(false);
|
|
}
|
|
std::cout<<surfaceArea<<std::endl;
|
|
}
|
|
}
|
|
int sum=0;
|
|
for (int x=-minX;x<=maxX;x++){
|
|
for (int y=-minY;y<=maxY;y++){
|
|
for (int z=-minZ;z<=maxZ;z++){
|
|
if (escape(x,y,z)){
|
|
sum++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
std::cout<<surfaceArea-sum<<std::endl;
|
|
|
|
return 0;
|
|
}
|
|
|