Primeros 2 dias de advent of code :3
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
a.out
|
||||||
200
2020/day_1/input
Normal file
200
2020/day_1/input
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
1211
|
||||||
|
1698
|
||||||
|
1787
|
||||||
|
1947
|
||||||
|
1888
|
||||||
|
444
|
||||||
|
1819
|
||||||
|
1890
|
||||||
|
1940
|
||||||
|
1884
|
||||||
|
1917
|
||||||
|
1814
|
||||||
|
1724
|
||||||
|
1561
|
||||||
|
1823
|
||||||
|
1266
|
||||||
|
1982
|
||||||
|
1826
|
||||||
|
1871
|
||||||
|
1692
|
||||||
|
1665
|
||||||
|
1081
|
||||||
|
1847
|
||||||
|
640
|
||||||
|
1861
|
||||||
|
1632
|
||||||
|
1916
|
||||||
|
1921
|
||||||
|
1450
|
||||||
|
1806
|
||||||
|
1950
|
||||||
|
1969
|
||||||
|
1757
|
||||||
|
1766
|
||||||
|
1799
|
||||||
|
422
|
||||||
|
1865
|
||||||
|
1934
|
||||||
|
1954
|
||||||
|
1640
|
||||||
|
1743
|
||||||
|
1812
|
||||||
|
1745
|
||||||
|
1574
|
||||||
|
1904
|
||||||
|
1510
|
||||||
|
1491
|
||||||
|
1977
|
||||||
|
1727
|
||||||
|
1979
|
||||||
|
1842
|
||||||
|
1784
|
||||||
|
1655
|
||||||
|
1991
|
||||||
|
1296
|
||||||
|
1849
|
||||||
|
1863
|
||||||
|
1886
|
||||||
|
1696
|
||||||
|
1716
|
||||||
|
1679
|
||||||
|
1848
|
||||||
|
1540
|
||||||
|
1780
|
||||||
|
1926
|
||||||
|
1986
|
||||||
|
1898
|
||||||
|
1448
|
||||||
|
315
|
||||||
|
1568
|
||||||
|
1869
|
||||||
|
1875
|
||||||
|
2010
|
||||||
|
1268
|
||||||
|
1892
|
||||||
|
1248
|
||||||
|
1746
|
||||||
|
1987
|
||||||
|
1963
|
||||||
|
20
|
||||||
|
1575
|
||||||
|
1827
|
||||||
|
1653
|
||||||
|
1851
|
||||||
|
1365
|
||||||
|
1599
|
||||||
|
1688
|
||||||
|
1943
|
||||||
|
1677
|
||||||
|
1320
|
||||||
|
154
|
||||||
|
1490
|
||||||
|
1737
|
||||||
|
1573
|
||||||
|
1908
|
||||||
|
1667
|
||||||
|
1151
|
||||||
|
1761
|
||||||
|
1587
|
||||||
|
1924
|
||||||
|
1941
|
||||||
|
1731
|
||||||
|
1669
|
||||||
|
1857
|
||||||
|
1723
|
||||||
|
1880
|
||||||
|
1970
|
||||||
|
1791
|
||||||
|
1928
|
||||||
|
1942
|
||||||
|
1816
|
||||||
|
1989
|
||||||
|
1832
|
||||||
|
1911
|
||||||
|
1711
|
||||||
|
1817
|
||||||
|
1893
|
||||||
|
896
|
||||||
|
1998
|
||||||
|
1720
|
||||||
|
317
|
||||||
|
1964
|
||||||
|
1379
|
||||||
|
1750
|
||||||
|
1971
|
||||||
|
1322
|
||||||
|
1992
|
||||||
|
1347
|
||||||
|
1608
|
||||||
|
1373
|
||||||
|
1668
|
||||||
|
1252
|
||||||
|
373
|
||||||
|
1968
|
||||||
|
1754
|
||||||
|
1709
|
||||||
|
1988
|
||||||
|
1946
|
||||||
|
1537
|
||||||
|
1758
|
||||||
|
1830
|
||||||
|
624
|
||||||
|
1694
|
||||||
|
1914
|
||||||
|
1867
|
||||||
|
1145
|
||||||
|
1973
|
||||||
|
1769
|
||||||
|
1773
|
||||||
|
1424
|
||||||
|
1777
|
||||||
|
1659
|
||||||
|
1789
|
||||||
|
1907
|
||||||
|
1201
|
||||||
|
1967
|
||||||
|
1682
|
||||||
|
1952
|
||||||
|
1978
|
||||||
|
1937
|
||||||
|
1974
|
||||||
|
1488
|
||||||
|
1896
|
||||||
|
1657
|
||||||
|
1420
|
||||||
|
1935
|
||||||
|
1778
|
||||||
|
1822
|
||||||
|
1703
|
||||||
|
2003
|
||||||
|
119
|
||||||
|
1149
|
||||||
|
1732
|
||||||
|
1878
|
||||||
|
1938
|
||||||
|
1918
|
||||||
|
1797
|
||||||
|
1836
|
||||||
|
1741
|
||||||
|
1579
|
||||||
|
1589
|
||||||
|
1999
|
||||||
|
1772
|
||||||
|
1853
|
||||||
|
1793
|
||||||
|
1768
|
||||||
|
1759
|
||||||
|
1216
|
||||||
|
1765
|
||||||
|
1944
|
||||||
|
1735
|
||||||
|
1580
|
||||||
|
1756
|
||||||
|
1308
|
||||||
|
1786
|
||||||
|
1962
|
||||||
|
1981
|
||||||
|
1156
|
||||||
|
1948
|
||||||
|
1894
|
||||||
36
2020/day_1/report_repair.cpp
Normal file
36
2020/day_1/report_repair.cpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <set>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::set<int> read_input_file() {
|
||||||
|
std::ifstream file("input");
|
||||||
|
std::set<int> data;
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while(std::getline(file, line))
|
||||||
|
data.insert(std::stoi(line));
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
auto data = read_input_file();
|
||||||
|
int iterations = 0;
|
||||||
|
|
||||||
|
for(auto &i: data) {
|
||||||
|
int rest = 2020 - i;
|
||||||
|
|
||||||
|
for(auto &j: data) {
|
||||||
|
int second_rest = rest - j;
|
||||||
|
if (data.count(second_rest)) {
|
||||||
|
std::cout << i * j * second_rest << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
21
2020/day_1/report_repair.py
Normal file
21
2020/day_1/report_repair.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
def solve(data):
|
||||||
|
iterations = 0
|
||||||
|
for x in range(len(data)):
|
||||||
|
rest = 2020 - data[x]
|
||||||
|
|
||||||
|
for y in range(x + 1, len(data)):
|
||||||
|
iterations += 1
|
||||||
|
second_rest = rest - data[y]
|
||||||
|
|
||||||
|
if second_rest in data:
|
||||||
|
print((data[x], data[y], second_rest), (iterations), data[x] * data[y] * second_rest)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
with open('input') as f:
|
||||||
|
data = [int(line) for line in f]
|
||||||
|
data.sort()
|
||||||
|
|
||||||
|
solve(data)
|
||||||
|
|
||||||
1000
2020/day_2/input
Normal file
1000
2020/day_2/input
Normal file
File diff suppressed because it is too large
Load Diff
56
2020/day_2/password_philosophy.cpp
Normal file
56
2020/day_2/password_philosophy.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::vector<std::string> read_input_file() {
|
||||||
|
std::ifstream file("input");
|
||||||
|
std::vector<std::string> data;
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while(std::getline(file, line))
|
||||||
|
data.push_back(line);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> split(const std::string &s, char delimiter) {
|
||||||
|
std::vector<std::string> tokens;
|
||||||
|
std::string token;
|
||||||
|
std::istringstream token_stream(s);
|
||||||
|
|
||||||
|
while(std::getline(token_stream, token, delimiter))
|
||||||
|
tokens.push_back(token);
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
auto data = read_input_file();
|
||||||
|
|
||||||
|
int result_a = 0;
|
||||||
|
int result_b = 0;
|
||||||
|
|
||||||
|
for(auto &line: data) {
|
||||||
|
auto main_split = split(line, ' ');
|
||||||
|
auto number_split = split(main_split[0], '-');
|
||||||
|
|
||||||
|
int first = stoi(number_split[0]);
|
||||||
|
int second = stoi(number_split[1]);
|
||||||
|
char letter = main_split[1][0];
|
||||||
|
std::string password = main_split[2];
|
||||||
|
|
||||||
|
int count = std::count(password.begin(), password.end(), letter);
|
||||||
|
|
||||||
|
if(first <= count && count <= second)
|
||||||
|
result_a++;
|
||||||
|
if((password[first - 1] == letter) ^ (password[second - 1] == letter))
|
||||||
|
result_b++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << result_a << ' ' << result_b << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
23
2020/day_2/password_philosophy.py
Normal file
23
2020/day_2/password_philosophy.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
with open('input') as f:
|
||||||
|
data = [line.strip().split(' ') for line in f]
|
||||||
|
|
||||||
|
def first_policy(first, second, letter, password):
|
||||||
|
return first <= password.count(letter) <= second
|
||||||
|
|
||||||
|
def second_policy(first, second, letter, password):
|
||||||
|
return (password[first - 1] == letter) ^ (password[second - 1] == letter)
|
||||||
|
|
||||||
|
def analyze(policy):
|
||||||
|
result = 0
|
||||||
|
for line in data:
|
||||||
|
first, second= [int(i) for i in line[0].split('-')]
|
||||||
|
letter = line[1].replace(':', '')
|
||||||
|
password = line[2]
|
||||||
|
|
||||||
|
if policy(first, second, letter, password):
|
||||||
|
result += 1
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
print(analyze(first_policy))
|
||||||
|
print(analyze(second_policy))
|
||||||
Reference in New Issue
Block a user