Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit17d51d5

Browse files
author
Lukasz
committed
AoC 2021
1 parent77c6030 commit17d51d5

File tree

5 files changed

+259
-0
lines changed

5 files changed

+259
-0
lines changed

‎advent-of-code/2021/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug/
4+
target/
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8+
Cargo.lock
9+
10+
# These are backup files generated by rustfmt
11+
**/*.rs.bk
12+
13+
# MSVC Windows builds of rustc generate these, which store debugging information
14+
*.pdb

‎advent-of-code/2021/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#Advent of code 2021 solutions in RUST by luk6xff

‎advent-of-code/2021/day01/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name ="day01"
3+
version ="0.1.0"
4+
authors = ["luk6xff <lukasz.uszko@gmail.com>"]
5+
edition ="2021"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
itertools ="0.9"

‎advent-of-code/2021/day01/input.txt

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1082
2+
1770
3+
1104
4+
1180
5+
1939
6+
1952
7+
1330
8+
1569
9+
1120
10+
1281
11+
1144
12+
1091
13+
2008
14+
1967
15+
1863
16+
1819
17+
1813
18+
1986
19+
1099
20+
1860
21+
1686
22+
1063
23+
1620
24+
1107
25+
1095
26+
951
27+
1897
28+
1246
29+
1264
30+
1562
31+
1151
32+
1980
33+
1942
34+
1416
35+
1170
36+
1258
37+
1075
38+
1882
39+
1329
40+
2003
41+
66
42+
1249
43+
1302
44+
1221
45+
1828
46+
1154
47+
1662
48+
1103
49+
1879
50+
1205
51+
1936
52+
1472
53+
1816
54+
1071
55+
1237
56+
1467
57+
1919
58+
942
59+
74
60+
1178
61+
1949
62+
1947
63+
1613
64+
1931
65+
1332
66+
24
67+
1987
68+
1796
69+
1256
70+
1981
71+
1158
72+
1114
73+
2004
74+
1696
75+
1775
76+
1718
77+
1102
78+
1998
79+
1540
80+
1129
81+
1870
82+
1841
83+
1582
84+
1173
85+
1417
86+
1604
87+
1214
88+
1941
89+
1440
90+
1381
91+
1149
92+
1111
93+
1766
94+
1747
95+
1940
96+
960
97+
1449
98+
1171
99+
1584
100+
1926
101+
1065
102+
1832
103+
1633
104+
1245
105+
1889
106+
1906
107+
1198
108+
1959
109+
1340
110+
1951
111+
1347
112+
1097
113+
1660
114+
1957
115+
1134
116+
1730
117+
1105
118+
1124
119+
1073
120+
1679
121+
1397
122+
1963
123+
1136
124+
1983
125+
1806
126+
1964
127+
1821
128+
1997
129+
1254
130+
1823
131+
1092
132+
1119
133+
2000
134+
1089
135+
1933
136+
1478
137+
1923
138+
1576
139+
1571
140+
415
141+
1875
142+
1937
143+
1112
144+
1831
145+
1969
146+
1506
147+
1929
148+
1960
149+
1322
150+
110
151+
1141
152+
1080
153+
1603
154+
1126
155+
1036
156+
1762
157+
1904
158+
1122
159+
1988
160+
1962
161+
1958
162+
1953
163+
1068
164+
1188
165+
1483
166+
1518
167+
1471
168+
1961
169+
1217
170+
1559
171+
1789
172+
1523
173+
2007
174+
1093
175+
1745
176+
1955
177+
1948
178+
1474
179+
1628
180+
691
181+
1398
182+
1876
183+
1650
184+
1838
185+
1950
186+
1088
187+
1697
188+
1977
189+
1364
190+
1966
191+
1945
192+
1975
193+
1606
194+
1974
195+
1847
196+
1570
197+
1148
198+
1599
199+
1772
200+
1970

‎advent-of-code/2021/day01/src/main.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use itertools::Itertools;
2+
3+
fnparse_input(input:&str) ->Vec<i32>{
4+
input.lines()
5+
.filter_map(|n| n.parse::<i32>().ok())
6+
.collect()
7+
}
8+
9+
fncombination_summing_to_n(input:&[i32],k_combinations:usize,n:i32) ->Option<Vec<i32>>{
10+
input.iter()
11+
.copied()
12+
.combinations(k_combinations)
13+
.find(|v| v.iter().sum::<i32>() == n)
14+
}
15+
16+
fncommon_solution(k_combinations:usize){
17+
let input =parse_input(include_str!("../input.txt"));
18+
matchcombination_summing_to_n(&input, k_combinations,2020){
19+
Some(s) =>println!("Solution: {}", s.iter().product::<i32>()),
20+
None =>println!("No solution found"),
21+
}
22+
}
23+
24+
fnpart_1(){
25+
common_solution(2)
26+
}
27+
fnpart_2(){
28+
common_solution(3)
29+
}
30+
31+
fnmain(){
32+
part_1();
33+
part_2();
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp