day01
This commit is contained in:
commit
77e9d3eb96
5 changed files with 259 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
Cargo.lock
|
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "aoc2020"
|
||||
version = "0.1.0"
|
||||
authors = ["Stefan Schwarz <ssz@bitsbeats.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
|
||||
[[bin]]
|
||||
name = "day01"
|
||||
path = "src/day01/main.rs"
|
200
input01
Normal file
200
input01
Normal file
|
@ -0,0 +1,200 @@
|
|||
1728
|
||||
1621
|
||||
1856
|
||||
1683
|
||||
1940
|
||||
1097
|
||||
1711
|
||||
1906
|
||||
2008
|
||||
1608
|
||||
2003
|
||||
1990
|
||||
1864
|
||||
1035
|
||||
1981
|
||||
1978
|
||||
1955
|
||||
1907
|
||||
1198
|
||||
1087
|
||||
1835
|
||||
1961
|
||||
1941
|
||||
1903
|
||||
1675
|
||||
417
|
||||
1842
|
||||
1802
|
||||
1639
|
||||
1601
|
||||
1546
|
||||
1909
|
||||
1061
|
||||
1031
|
||||
1996
|
||||
1717
|
||||
1972
|
||||
1900
|
||||
1443
|
||||
1873
|
||||
1851
|
||||
2010
|
||||
1650
|
||||
1975
|
||||
1002
|
||||
1142
|
||||
1747
|
||||
1640
|
||||
1924
|
||||
1824
|
||||
1539
|
||||
1937
|
||||
1715
|
||||
1871
|
||||
1867
|
||||
1428
|
||||
1861
|
||||
1914
|
||||
1986
|
||||
1976
|
||||
1111
|
||||
1858
|
||||
1869
|
||||
1899
|
||||
1171
|
||||
1041
|
||||
1662
|
||||
1222
|
||||
1709
|
||||
1889
|
||||
1950
|
||||
1960
|
||||
1989
|
||||
1737
|
||||
1600
|
||||
1444
|
||||
1725
|
||||
1710
|
||||
1653
|
||||
1745
|
||||
1922
|
||||
1945
|
||||
1189
|
||||
1917
|
||||
1891
|
||||
1718
|
||||
1997
|
||||
1631
|
||||
1053
|
||||
1750
|
||||
1634
|
||||
1822
|
||||
1706
|
||||
1160
|
||||
1619
|
||||
1665
|
||||
1687
|
||||
1648
|
||||
1818
|
||||
1655
|
||||
1736
|
||||
1881
|
||||
489
|
||||
1598
|
||||
1923
|
||||
1962
|
||||
1918
|
||||
1689
|
||||
1616
|
||||
1825
|
||||
1723
|
||||
1767
|
||||
591
|
||||
1734
|
||||
1949
|
||||
1645
|
||||
1344
|
||||
1959
|
||||
1758
|
||||
1068
|
||||
1843
|
||||
1826
|
||||
1849
|
||||
2005
|
||||
1777
|
||||
144
|
||||
2009
|
||||
1982
|
||||
1911
|
||||
1288
|
||||
1595
|
||||
1094
|
||||
2000
|
||||
1713
|
||||
1973
|
||||
1971
|
||||
1916
|
||||
1666
|
||||
1105
|
||||
1806
|
||||
1868
|
||||
1944
|
||||
1654
|
||||
1809
|
||||
1726
|
||||
1672
|
||||
1060
|
||||
1065
|
||||
1521
|
||||
1921
|
||||
1966
|
||||
1113
|
||||
1149
|
||||
1607
|
||||
1980
|
||||
1023
|
||||
1855
|
||||
1948
|
||||
1638
|
||||
1930
|
||||
1866
|
||||
1954
|
||||
1697
|
||||
1884
|
||||
1832
|
||||
2004
|
||||
914
|
||||
1845
|
||||
1043
|
||||
1854
|
||||
1223
|
||||
1913
|
||||
1984
|
||||
1910
|
||||
1793
|
||||
1878
|
||||
1248
|
||||
617
|
||||
1927
|
||||
1527
|
||||
1819
|
||||
1350
|
||||
1807
|
||||
1722
|
||||
1016
|
||||
1700
|
||||
111
|
||||
1629
|
||||
1932
|
||||
1644
|
||||
1454
|
||||
1987
|
||||
1925
|
||||
1953
|
||||
1743
|
||||
1180
|
||||
1782
|
||||
1523
|
||||
1245
|
||||
1620
|
36
src/day01/main.rs
Normal file
36
src/day01/main.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use anyhow::Result;
|
||||
use std::io::prelude::*;
|
||||
use std::io::stdin;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let nums: Vec<i64> = stdin()
|
||||
.lock()
|
||||
.lines()
|
||||
.map(|line| {
|
||||
line.expect("unable to read input")
|
||||
.parse::<i64>()
|
||||
.expect("input is not a number")
|
||||
})
|
||||
.collect();
|
||||
'outer: for a in nums.iter() {
|
||||
for b in nums.iter() {
|
||||
if a + b == 2020 {
|
||||
println!("{} + {} = 2020", a, b);
|
||||
println!("product: {}", a * b);
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
'outer: for a in nums.iter() {
|
||||
for b in nums.iter() {
|
||||
for c in nums.iter() {
|
||||
if a + b + c == 2020 {
|
||||
println!("{} + {} + {} = 2020", a, b, c);
|
||||
println!("product: {}", a * b * c);
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
7
src/lib.rs
Normal file
7
src/lib.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue