Skip to content

Instantly share code, notes, and snippets.

@willeccles
Last active December 8, 2015 22:13
Show Gist options
  • Save willeccles/0a893f5bb81441b9181c to your computer and use it in GitHub Desktop.
Save willeccles/0a893f5bb81441b9181c to your computer and use it in GitHub Desktop.
Part 1 of Day 8 of Advent of Code. The reason for it being a whole new class called Day8 is that I use a single main.cpp to run each day's code, just instantiating a Day6, 7, 8, etc... and using the run() method.
#include "stdafx.h"
#include "Day8.h"
#include <iostream>
#include <string>
#include <fstream>
#include <regex>
using namespace std;
// this is just to make my code later on cleaner and simpler, whereas up here I don't really care.
#define REG_REPLACE(str) regex_replace(regex_replace(regex_replace(regex_replace(str, memquotes, ""), doubleslash, "_"), asciihex, "_"), actualquotes, "_")
string &lines = string("");
string &memlines = string("");
regex memquotes("^\"|\"$");
regex doubleslash("\\\\\\\\");
regex asciihex("\\\\x[a-zA-Z0-9]{2}");
regex actualquotes("\\\\\"");
void Day8::run() {
lines = "";
memlines = "";
cout << "Storing all lines... ";
fstream file("Day 8 Input.txt");
string line;
while (getline(file, line)) {
lines += REG_REPLACE(line);
memlines += line;
}
cout << "DONE" << endl;
cout << endl << "Done!" << endl;
cout << "Length in memory: " << memlines.length() << endl;
cout << "Actual length: " << lines.length() << endl;
cout << "Difference: " << memlines.length() - lines.length() << endl;
cin.get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment