From 77e9d3eb96031cafbcd4522e13ff3dc738ef90b9 Mon Sep 17 00:00:00 2001 From: Stefan Schwarz Date: Tue, 1 Dec 2020 08:20:00 +0100 Subject: [PATCH] day01 --- .gitignore | 2 + Cargo.toml | 14 ++++ input01 | 200 ++++++++++++++++++++++++++++++++++++++++++++++ src/day01/main.rs | 36 +++++++++ src/lib.rs | 7 ++ 5 files changed, 259 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 input01 create mode 100644 src/day01/main.rs create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e9179ce --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "aoc2020" +version = "0.1.0" +authors = ["Stefan Schwarz "] +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" diff --git a/input01 b/input01 new file mode 100644 index 0000000..c13d4c4 --- /dev/null +++ b/input01 @@ -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 diff --git a/src/day01/main.rs b/src/day01/main.rs new file mode 100644 index 0000000..d5b9567 --- /dev/null +++ b/src/day01/main.rs @@ -0,0 +1,36 @@ +use anyhow::Result; +use std::io::prelude::*; +use std::io::stdin; + +fn main() -> Result<()> { + let nums: Vec = stdin() + .lock() + .lines() + .map(|line| { + line.expect("unable to read input") + .parse::() + .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(()) +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..31e1bb2 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +}