Skip to content

Commit d409d8d

Browse files
author
Linus Kardell
committed
Add day 1
1 parent f49cc6a commit d409d8d

File tree

6 files changed

+253
-1
lines changed

6 files changed

+253
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Generated by Cargo
22
# will have compiled files and executables
3-
/target/
3+
target/
44

55
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
66
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

Day1_input.txt

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1688
2+
1463
3+
1461
4+
1842
5+
1441
6+
1838
7+
1583
8+
1891
9+
1876
10+
1551
11+
1506
12+
2005
13+
1989
14+
1417
15+
1784
16+
1975
17+
1428
18+
1485
19+
1597
20+
1871
21+
105
22+
788
23+
1971
24+
1892
25+
1854
26+
1466
27+
1584
28+
1565
29+
1400
30+
1640
31+
1780
32+
1774
33+
360
34+
1421
35+
1368
36+
1771
37+
1666
38+
1707
39+
1627
40+
1449
41+
1677
42+
1504
43+
1721
44+
1994
45+
1959
46+
1862
47+
1768
48+
1986
49+
1904
50+
1382
51+
1969
52+
1852
53+
1917
54+
1966
55+
1742
56+
1371
57+
1405
58+
1995
59+
1906
60+
1694
61+
1735
62+
1422
63+
1719
64+
1978
65+
1641
66+
1761
67+
1567
68+
1974
69+
1495
70+
1973
71+
1958
72+
1599
73+
1770
74+
1600
75+
1465
76+
1865
77+
1479
78+
1687
79+
1390
80+
1802
81+
2008
82+
645
83+
1435
84+
1589
85+
1949
86+
1909
87+
1526
88+
1667
89+
1831
90+
1864
91+
1713
92+
1718
93+
1232
94+
1868
95+
1884
96+
1825
97+
1999
98+
1590
99+
1759
100+
1391
101+
1757
102+
323
103+
1612
104+
1637
105+
1727
106+
1783
107+
1643
108+
1442
109+
1452
110+
675
111+
1812
112+
1604
113+
1518
114+
1894
115+
1933
116+
1801
117+
1914
118+
912
119+
1576
120+
1961
121+
1970
122+
1446
123+
1985
124+
1988
125+
1563
126+
1826
127+
1409
128+
1503
129+
1539
130+
1832
131+
1698
132+
1990
133+
1689
134+
1532
135+
765
136+
1546
137+
1384
138+
1519
139+
1615
140+
1556
141+
1754
142+
1983
143+
1394
144+
1763
145+
1823
146+
1788
147+
1407
148+
1946
149+
1751
150+
1837
151+
1680
152+
1929
153+
1814
154+
1948
155+
1919
156+
1953
157+
55
158+
1731
159+
1516
160+
1895
161+
1795
162+
1890
163+
1881
164+
1799
165+
1536
166+
1396
167+
1942
168+
1798
169+
1767
170+
1745
171+
1883
172+
2004
173+
1550
174+
1916
175+
1650
176+
1749
177+
1991
178+
1789
179+
1740
180+
1490
181+
1873
182+
1003
183+
1699
184+
1669
185+
1781
186+
2000
187+
1728
188+
1877
189+
1733
190+
1588
191+
1168
192+
1828
193+
1848
194+
1963
195+
1928
196+
1920
197+
1493
198+
1968
199+
1564
200+
1572

day1a/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "day1a"
3+
version = "0.1.0"
4+
authors = ["linus"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

day1a/src/main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::io;
2+
use std::io::Read;
3+
4+
fn main() {
5+
let mut input = String::new();
6+
io::stdin().read_to_string(&mut input).unwrap();
7+
let numbers: Vec<u32> = input.lines().map(|x| x.parse().unwrap()).collect();
8+
'outer: for (n, i) in numbers.iter().enumerate() {
9+
for j in numbers.iter().skip(n + 1) {
10+
if i + j == 2020 {
11+
println!("{}", i * j);
12+
break 'outer;
13+
}
14+
}
15+
}
16+
}

day1b/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "day1b"
3+
version = "0.1.0"
4+
authors = ["linus"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

day1b/src/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::io;
2+
use std::io::Read;
3+
4+
fn main() {
5+
let mut input = String::new();
6+
io::stdin().read_to_string(&mut input).unwrap();
7+
let numbers: Vec<u32> = input.lines().map(|x| x.parse().unwrap()).collect();
8+
'outer: for (n, i) in numbers.iter().enumerate() {
9+
for (m, j) in numbers.iter().enumerate().skip(n + 1) {
10+
for k in numbers.iter().skip(m + 1) {
11+
if i + j + k == 2020 {
12+
println!("{}", i * j * k);
13+
break 'outer;
14+
}
15+
}
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)