Last active
December 1, 2020 20:52
-
-
Save mkosler/7d09a3632150e280077416b6cc9de5f9 to your computer and use it in GitHub Desktop.
Advent of Code 2020: Day 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <vector> | |
int main(int argc, char* argv[]) | |
{ | |
std::vector<int> expenses; | |
std::stringstream ss; | |
ss << std::cin.rdbuf(); | |
for (int n = 0; ss >> n; ) { | |
expenses.push_back(n); | |
} | |
for (int i = 0; i < expenses.size(); i++) { | |
int a = expenses[i]; | |
for (int j = 0; j < expenses.size(); j++) { | |
int b = expenses[j]; | |
if (i != j && a + b == 2020) { | |
std::cout << a << " " << b << " " << a * b << std::endl; | |
return 0; | |
} | |
} | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local expense = {} | |
for l in io.lines() do | |
table.insert(expense, tonumber(l)) | |
end | |
for _,a in pairs(expense) do | |
for _,b in pairs(expense) do | |
if a ~= b and a + b == 2020 then | |
print(a, b, a * b) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <vector> | |
int main(int argc, char* argv[]) | |
{ | |
std::vector<int> expenses; | |
std::stringstream ss; | |
ss << std::cin.rdbuf(); | |
for (int n = 0; ss >> n; ) { | |
expenses.push_back(n); | |
} | |
for (int i = 0; i < expenses.size(); i++) { | |
int a = expenses[i]; | |
for (int j = 0; j < expenses.size(); j++) { | |
int b = expenses[j]; | |
for (int k = 0; k < expenses.size(); k++) { | |
int c = expenses[k]; | |
if (i != j && i != k && j != k && a + b + c == 2020) { | |
std::cout << a << " " << b << " " << c << " " << a * b * c << std::endl; | |
return 0; | |
} | |
} | |
} | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local expense = {} | |
for l in io.lines() do | |
table.insert(expense, tonumber(l)) | |
end | |
for _,a in pairs(expense) do | |
for _,b in pairs(expense) do | |
for _,c in pairs(expense) do | |
if a ~= b and b ~= c and a ~= c and a + b + c == 2020 then | |
print(a, b, c, a * b * c) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment