diff --git a/2022/6/Makefile b/2022/6/Makefile new file mode 100644 index 0000000..385fff6 --- /dev/null +++ b/2022/6/Makefile @@ -0,0 +1,6 @@ +all: a.out b.out +a.out: main.cpp + clang++ -std=c++2b -g -O0 main.cpp + +b.out: main2.cpp + clang++ -std=c++2b -g -O0 main2.cpp -o b.out diff --git a/2022/6/b.out b/2022/6/b.out new file mode 100755 index 0000000..0f27432 Binary files /dev/null and b/2022/6/b.out differ diff --git a/2022/6/data.txt b/2022/6/data.txt new file mode 100644 index 0000000..5f190e2 --- /dev/null +++ b/2022/6/data.txt @@ -0,0 +1 @@ +hqhnqhqshhslswsffchfcfbblvlblqlggfwwqfwwqdddbbbhzhjjrqjqbjqjwqjwqwhwrrmcrrjqjjlllcvcrrnpptzpzmmswmmzrzjrrfcrfccpbpzzvrrdndllttwftwwgzzwhwggdvdnnlrnncscbcfcctchcdchdccztzgzjjtdtcdtcchrrgpgzgsgpsggvtvppdccfhcfclfcfdfnddlbbptbtdbtdtjdjgdjjzljlssgbgcgqcqzccfnftfjjsgstggsngsscvssjzjnjtntvnvssrqqhtqtvqtvvjbvvbnvvqvmvrmmdsdvdwwnbnvbnvvcgvcczcfzftfsfrfsfttldtdrrgrgmgbbdvvbqbhqbqlqsqbsbpbgbvgbgwwrswrwrwttvnnzdnzzwggrmrfmmvllzwlwzzlvlbvllgsllpnlnvncvcvqqrwwcmcczhchzczbccdwcwvwzwwvddlwlhljlqjqnncntnctczzmwmlmccpggljlssqswsmmpvmvwvrrcpcrprmprrtdrtdrrsjsmshmmdpdlppbnbvvmmflmmjvjhvhjvjsjbjwjvvblvbvlbbllwlslvljvlvdvdgvgcchnhpnhnvhhtfhhvssczztlzzgvvqqghqgqssdscsnsrsmrmmwgwmgmlmdmggbgzbgzgdzdzccghgfgddtntftddpdrdrmrjmmmzttqmttnwngggtgtqtqnqhnqqpnnntrntrnnshhjtjzzfqqblqqlblslflmlttcwtwzzrlrnrcrrrgtrrftfhthzhggwggvgvvfvddcnddfjddzqzrrvtrvrfrrgpgrgngsgddlmddzgzppdzzjzhjhjhqqbpbvvlrvrsvrvnrrsgsttndnbngnppmlppvgvfggvcvrvnnsnfnnfqfwwppnddrrfqqgbqqfmmlnlnngwgcgjgnjgjsgjgqjjnccdttpqttswwcgcmgmccrppmqmbbfwwvdwdfwfjwfjjblldsdrdvvgcvcwwllfpllcslsvssnvsnvvhnvnvwwcgwccslsbbnlbnbrrrtprptpdpdvdttgsgwswppcdchhqbqcbqbzbgbbstshthsttqgtqtpqqzhhwhghwwmbbdlbbtlltsllbvbnvvmqvqtvqvttlwtltmmrttwgtwwfdddwcchtchhbthbbclczzqbzzpvvwzwswggjddntnrnnwmnnbdbmbccqgqvvsnvvqbvbzvvzmvzzrfrlfrfhhdvddnmnnmhmqhhrhlrldljlbljjgqqvdvhhgmgvgddmmznndmmhssznsswvwdvdzdhhscssntnftfmmrggbmbmgmlltctbtbntnqqscqcscrcrhrlhhdchhzccvvbfvvpfffbwbsbjjmgmwgmgppjnpjphhlmhhpwwhwzhhhzbbzzcbchhpnnptpvphhsdsccffqbqllchlhlwlcljlppnccqsstzstswtwwljwjmmpttvqqspsjjclljqqlhqqtnnbrrsbrbjjllrmrjmjzmmclmclmmcvvbddhnnmhmbbwqqqhrqqtqmqbqdbdtdvvcscshccmffhqffdgdcgddljdjbdbjbdbrrtjjtnntpntpnpmnpmpgghffrnfrnnmdnmnhmmjcjffftrrttfwfvwvcwwrmwmpwmmnvntthmmgmbbcdclcppjhpjhjwwlppgsszqqwggmttfrfqflfsfmmmhchshmmjtjjgdjjnnsvsmsnwcgdfqljmnphlfdrhpggfqnhnszgpndhdqcgfhtdcgbsbtmhvnnrmqzqqcjdqndzbnrhwjvbvcldmnwltgpqbmstntnggtbqjzzqrfdsfttdfrcnsrpwrjrjqbgtjfmlwsrzdbdqvbtczgsjqhtgmctjfmdglfrsvqtgwpbqghzgzdfwzhbdhlmhdvhwjrdhhtjptvwpmjnmfcjdmdczmczvdqwvbgtvlwvwnvdlbqfshmlmvzzcmjbtpwpwgsqhfsgljzhbppcztfjdntzcvllqnzrqjwfjrlgvhmbpvbtqjrdzcsmcjzcdsmvcmhrbhgnscnfrfmscqsqpqplbrzhsrlsvvpmfdtdmtlrtvspmlljmfpshfmstjgnrrwmqlbnwbndcfdstrtqtnzpfqlcgrzmsnmhllljdgtmvftjttbwhqzcqwbwdbshgcqrptfjwbbfsjnvzztlbdchqrlbbrcnsswmhwphfwrbnvrncbrthprmltlwwlfpbqhdfqzwwcwjgqzdnvmhwpzpbtpwwvzcpfcsfqpwjljzzfwzmlfvhsccppzlzjlrvlpdtjpcptnvqjwtdbzrqwnfwmmjndflqqggczrfjlpdfjffctprnmhfdqvnzbfvhszzdmngnlmwzfdrbvlvjnmbllgrczssqcrhbmnpmqlrzgmqmhgsvcdlqnmlhlzvqzhnccbctslzlbcpdvqltqncpcrzwdchrqmwfwlcbcvfnnpjntfrznqdjsdtzqjjttddwvnfqmznhflblzvvtbwdzrrlqlmndzzzwnpbhhlvlbswfjtbnhlccscbnfgjtwbfdlwvzszwnwzhlbcdpvgqjcrpzsvvnfwqcqvrmhzhggvmzwggdpbfrdscjwhsdsbbjcnzldhzcvqtjrhsbfjlrlpvtcqhnnsvslfrdjvjhfhdcfzqchpvvhzbpqglqlrdttrdtndzhnzhtqndghtgmpsnhptprqzhbbdcrgmbvrvqmbptqgnmsccwmhrlpddvmhjntllwrzqwnsjchnblcgndjtmpswwgcstdftqcbhzgttrhnpvrhspjznhhvrlpdqbzzrvzjphcswhljdldvsrdhzltwgrcsvqwnhtqqjjrjgrplzmsnjhzrfbtqgdfgnbpvjrfzrrpdphgzrfbswdhzgbzswqtwwdtrvvswmjvwhqddfzjhgdqsfnwbmlcfwtmpldrdpwjwggbpmncvbghzjmpsqpvnmbhjfzzpsjdgmrtnndhzrphjzdbgrrnthtrfnspdngbdmwbnfjlsndqswfsvfqftqlgqjpfsfpmdbsjfrptvbpvflqgvlmmbchhghhrwmvdlrhlsdtvjjchwglcrwfsfnnbhjbtccbjsfwrbzrvgsbfnvzghhrqblqchjvdtrrbrwwwmfnczzmmrqdggsfrqbldbbfbbcthtsvpcnlbjjztwvhctbrjltqdwbzmrrfslbmjpnqwllbvjzgfsfqqtwbgwgclgdflshfhwggwdqlgbmdmdqglrtfwbddtsltmsvswhgjtqwtnrncpdzhnpfqcjnjzmtbjfzpjwgfbfggmsmfdhfbjctnhchpgfspthdbfpmvrmdbbspvwzqqwnmfwdnnblbcjszbccgflngnjjwsqshfbhjwgzrmvsgnrdbgwfhdvpmznpnvznfcqdclztcptjrrpbmpztwwbvlvtmngfhmfbfmrjbjzlrcvgllrlgthltstnwmffntqrwsrndlzqhztwpcwbdjjztgdzmgtthcvtvnjzzhvstfqhgddddgdsrbcqzqspjrncphhtbnslzphrtfqphffjrrlgwbrwqfzzqvzhnffcwvrncttgplshccglvchvlcbnlthhmzvcrfjvjqfsjjzzgqlpslfwngqnbgcwffpcqhlmlhvwssrpjbrcbftpzbbpptzrdqwpzpdjhtwbvwcqbfnwtflfgzgttglpcwdnzsmjffgfftdnpzlpszmzrrhvlzdfpgbzqlvvfslnndcmjvvpwzwcdzpcttfwbsdswmfqbbhbfbjvbvtspbbhmphzjsjcmmzpvvzhtvzlgwlqqvbnrgtszvghjfmchrwwhpmbsvfmgvqdtmvdtjppchbsgqrtgtnzczqmpgjdbmmflfpjbcdmhldwpgdtdvsbzhztjzfhcsbndfjntbldjnqwdffqspfnlplbtcdjtwdjhldtsdfrnmpfhzghnpcqlhhgblmqjvwhndqfbccvzzlbzbdprvcpwjjhrqnjptwssbjhgvpgtfzqwrzjvbdgwtnmptvdjrffcmbzmzcmrfbjv diff --git a/2022/6/main.cpp b/2022/6/main.cpp new file mode 100644 index 0000000..ce0ab81 --- /dev/null +++ b/2022/6/main.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include + +bool Unique(const std::deque &buf) +{ + std::set s; + for(const char &ch : buf) + s.insert(ch); + return (s.size() == 4); +} + +int main() +{ + std::ifstream ifs("data.txt"); + if(!ifs.is_open()) + { + std::cerr << "Missing data.txt." << std::endl; + return -1; + } + + for(std::string line; std::getline(ifs, line); ) + { + if(line == "") + continue; + + std::deque buf; + + int idx = 0; + for(const char &ch : line) + { + ++idx; + buf.push_back(ch); + if(buf.size() >= 4) + { + while(buf.size() > 4) + buf.pop_front(); + + if(Unique(buf)) + { + std::cout << "At index " << idx << ": "; + for(const char &ch : buf) + std::cout << ch; + std::cout << std::endl; + + break; + } + } + } + } + + return 0; +} diff --git a/2022/6/main2.cpp b/2022/6/main2.cpp new file mode 100644 index 0000000..0fa768e --- /dev/null +++ b/2022/6/main2.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +int main() +{ + std::ifstream ifs("data.txt"); + if(!ifs.is_open()) + { + std::cerr << "Missing data.txt." << std::endl; + return -1; + } + + for(std::string line; std::getline(ifs, line); ) + { + if(line == "") + continue; + + std::vector buf; + + int idx = 0; + for(const char &ch : line) + { + ++idx; + + // clear out from beginning up until this character is found: + auto i = std::find(buf.begin(), buf.end(), ch); + if(i != buf.end()) + buf.erase(buf.begin(), i+1); + + buf.push_back(ch); + + if(buf.size() == 4) + { + std::cout << "Start-of-Packet at index " << idx << ": "; + for(const char &ch : buf) + std::cout << ch; + std::cout << std::endl; + } + else if(buf.size() == 14) + { + std::cout << "Start-of-Message at index " << idx << ": "; + for(const char &ch : buf) + std::cout << ch; + std::cout << std::endl; + } + } + } + + return 0; +} diff --git a/2022/starter/Makefile b/2022/starter/Makefile new file mode 100644 index 0000000..638e325 --- /dev/null +++ b/2022/starter/Makefile @@ -0,0 +1,2 @@ +a.out: main.cpp + clang++ -std=c++2b -g -O0 main.cpp diff --git a/2022/starter/main.cpp b/2022/starter/main.cpp new file mode 100644 index 0000000..a43dc5e --- /dev/null +++ b/2022/starter/main.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include + +int main() +{ + std::ifstream ifs("data.txt"); + if(!ifs.is_open()) + { + std::cerr << "Missing data.txt." << std::endl; + return -1; + } + + unsigned long total = 0; + unsigned long total_pt2 = 0; + + for(std::string line; std::getline(ifs, line); ) + { + if(line == "") + continue; + } + + std::cout << " Total: " << total << std::endl; + std::cout << "PT2 Total: " << total_pt2 << std::endl; + + return 0; +}