Skip to content

Commit 84aff4b

Browse files
committed
Day 1 part 1 complete in Rust
1 parent 506bb9c commit 84aff4b

File tree

5 files changed

+263
-0
lines changed

5 files changed

+263
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/target

2020/day-1/Cargo.lock

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2020/day-1/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "day-1"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
itertools = "0.10.0"

2020/day-1/input.txt

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1408
2+
1335
3+
1648
4+
1458
5+
1627
6+
1928
7+
1967
8+
1827
9+
1606
10+
1569
11+
1893
12+
1866
13+
1768
14+
1795
15+
1264
16+
1684
17+
1552
18+
1343
19+
1917
20+
1675
21+
1731
22+
1800
23+
1413
24+
1879
25+
1664
26+
1350
27+
1694
28+
1372
29+
1851
30+
1743
31+
1735
32+
833
33+
748
34+
1265
35+
1885
36+
1874
37+
2007
38+
1661
39+
1895
40+
1537
41+
1622
42+
1355
43+
762
44+
1533
45+
1771
46+
1966
47+
1978
48+
1572
49+
1833
50+
1969
51+
1805
52+
1820
53+
1536
54+
1911
55+
2009
56+
1817
57+
1268
58+
1998
59+
1759
60+
2008
61+
2002
62+
1187
63+
1896
64+
1850
65+
1734
66+
1849
67+
1589
68+
1302
69+
444
70+
1280
71+
1590
72+
1959
73+
902
74+
1709
75+
1932
76+
1277
77+
1561
78+
1301
79+
1831
80+
1286
81+
1693
82+
1927
83+
1467
84+
1384
85+
1662
86+
1401
87+
716
88+
1634
89+
1785
90+
1801
91+
1380
92+
1971
93+
1292
94+
1828
95+
185
96+
1560
97+
1322
98+
1787
99+
1545
100+
1395
101+
1445
102+
1807
103+
1750
104+
1867
105+
1433
106+
1894
107+
1821
108+
1983
109+
1578
110+
1669
111+
1610
112+
1549
113+
1556
114+
1346
115+
1616
116+
1999
117+
1925
118+
1387
119+
1659
120+
1457
121+
1237
122+
1808
123+
69
124+
1906
125+
1449
126+
1723
127+
1974
128+
1919
129+
1914
130+
1338
131+
1305
132+
1347
133+
1903
134+
1929
135+
1712
136+
1607
137+
1400
138+
197
139+
1575
140+
1282
141+
1296
142+
1737
143+
1396
144+
2003
145+
1453
146+
1660
147+
1646
148+
1991
149+
1565
150+
1416
151+
1995
152+
1784
153+
1367
154+
1420
155+
1593
156+
1654
157+
1306
158+
1916
159+
1797
160+
1594
161+
1471
162+
1405
163+
1698
164+
1541
165+
1900
166+
1963
167+
1696
168+
1574
169+
1853
170+
511
171+
1603
172+
1889
173+
1940
174+
1843
175+
1979
176+
272
177+
1726
178+
1294
179+
1877
180+
1441
181+
1697
182+
1644
183+
1956
184+
1689
185+
1665
186+
1631
187+
1717
188+
1781
189+
1450
190+
1618
191+
1317
192+
1799
193+
1950
194+
1722
195+
1960
196+
1628
197+
1941
198+
1977
199+
1775
200+
1529

2020/day-1/src/main.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use itertools::Itertools;
2+
use std::fs;
3+
4+
fn main() {
5+
println!("Hello, world!");
6+
7+
let lines = fs::read_to_string("input.txt").expect("Couldn't read input file.");
8+
let mut combos = lines
9+
.split("\n")
10+
.map(|val| val.parse::<u32>().expect("Nope!"))
11+
.combinations(2);
12+
13+
let result: Result<Vec<u32>, &str> = loop {
14+
match combos.next() {
15+
Some(val) if val[0] + val[1] == 2020 => break Ok(val),
16+
Some(_) => continue,
17+
None => break Err("Couldn't find matching pair"),
18+
};
19+
};
20+
21+
match result {
22+
Ok(val) => {
23+
println!("Found the combintation: {:?}", val);
24+
println!("The result is: {:?}", val[0] * val[1]);
25+
}
26+
Err(e) => println!("{}", e),
27+
}
28+
}

0 commit comments

Comments
 (0)