summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-12-01 22:35:23 -0500
committerJesse Luehrs <doy@tozt.net>2020-12-01 22:35:23 -0500
commitff32088cffa839acd41b68fdce1db1d6c7fd6165 (patch)
tree30b35757c853786ec50bd9b48aac59e193b1647d
parent6e7bcd5e4e9df984d40295860bba5a2b23893c18 (diff)
downloadadvent-of-code-ff32088cffa839acd41b68fdce1db1d6c7fd6165.tar.gz
advent-of-code-ff32088cffa839acd41b68fdce1db1d6c7fd6165.zip
puzzle 1-1
-rw-r--r--.rustfmt.toml1
-rw-r--r--Cargo.lock271
-rw-r--r--Cargo.toml3
-rw-r--r--data/1-1.txt200
-rw-r--r--src/2020/mod.rs33
-rw-r--r--src/main.rs24
6 files changed, 530 insertions, 2 deletions
diff --git a/.rustfmt.toml b/.rustfmt.toml
new file mode 100644
index 0000000..bcad605
--- /dev/null
+++ b/.rustfmt.toml
@@ -0,0 +1 @@
+max_width = 78
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..c55b2a0
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,271 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "advent-of-code"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "paw",
+ "structopt",
+]
+
+[[package]]
+name = "ansi_term"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "anyhow"
+version = "1.0.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bf8dcb5b4bbaa28653b647d8c77bd4ed40183b48882e130c1f1ffb73de069fd7"
+
+[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi",
+]
+
+[[package]]
+name = "bitflags"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
+
+[[package]]
+name = "clap"
+version = "2.33.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
+dependencies = [
+ "ansi_term",
+ "atty",
+ "bitflags",
+ "strsim",
+ "term_size",
+ "textwrap",
+ "unicode-width",
+ "vec_map",
+]
+
+[[package]]
+name = "heck"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
+dependencies = [
+ "unicode-segmentation",
+]
+
+[[package]]
+name = "hermit-abi"
+version = "0.1.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "lazy_static"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+
+[[package]]
+name = "libc"
+version = "0.2.80"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
+
+[[package]]
+name = "paw"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09c0fc9b564dbc3dc2ed7c92c0c144f4de340aa94514ce2b446065417c4084e9"
+dependencies = [
+ "paw-attributes",
+ "paw-raw",
+]
+
+[[package]]
+name = "paw-attributes"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0f35583365be5d148e959284f42526841917b7bfa09e2d1a7ad5dde2cf0eaa39"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "paw-raw"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f0b59668fe80c5afe998f0c0bf93322bf2cd66cafeeb80581f291716f3467f2"
+
+[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
+dependencies = [
+ "unicode-xid",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "strsim"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
+
+[[package]]
+name = "structopt"
+version = "0.3.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c"
+dependencies = [
+ "clap",
+ "lazy_static",
+ "paw",
+ "structopt-derive",
+]
+
+[[package]]
+name = "structopt-derive"
+version = "0.4.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90"
+dependencies = [
+ "heck",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "syn"
+version = "1.0.53"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8833e20724c24de12bbaba5ad230ea61c3eafb05b881c7c9d3cfe8638b187e68"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-xid",
+]
+
+[[package]]
+name = "term_size"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9"
+dependencies = [
+ "libc",
+ "winapi",
+]
+
+[[package]]
+name = "textwrap"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
+dependencies = [
+ "term_size",
+ "unicode-width",
+]
+
+[[package]]
+name = "unicode-segmentation"
+version = "1.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
+
+[[package]]
+name = "unicode-width"
+version = "0.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
+
+[[package]]
+name = "unicode-xid"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
+
+[[package]]
+name = "vec_map"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
+
+[[package]]
+name = "version_check"
+version = "0.9.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/Cargo.toml b/Cargo.toml
index 617ddc3..ad1246e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,3 +7,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+anyhow = "1.0"
+paw = "1.0"
+structopt = { version = "0.3", features = ["paw", "wrap_help"] }
diff --git a/data/1-1.txt b/data/1-1.txt
new file mode 100644
index 0000000..15a9273
--- /dev/null
+++ b/data/1-1.txt
@@ -0,0 +1,200 @@
+1511
+1344
+1925
+1970
+1864
+1951
+1557
+1984
+1743
+1526
+1972
+1945
+1969
+1760
+2008
+1592
+736
+1963
+1994
+2009
+1777
+1856
+1899
+1926
+1850
+687
+2005
+1094
+1949
+1326
+2002
+1805
+1493
+1341
+1828
+1778
+1767
+1364
+1973
+1768
+1929
+1377
+2000
+1726
+1913
+2001
+1574
+1859
+1793
+1957
+1959
+1388
+1593
+1392
+724
+1962
+1999
+252
+1982
+1662
+1892
+1610
+1343
+1831
+1862
+1991
+1394
+1946
+1935
+1986
+1911
+1358
+1322
+1956
+1988
+1758
+1490
+1998
+1744
+1844
+1294
+1764
+1543
+1560
+1562
+1747
+1870
+1292
+1989
+1752
+1471
+1980
+1897
+1544
+1914
+1923
+1944
+1375
+1987
+1993
+1742
+1975
+1479
+1977
+1934
+1939
+1950
+1992
+1983
+1474
+1643
+2010
+1814
+1942
+322
+1425
+1646
+1878
+1410
+1927
+1761
+1948
+1779
+1753
+1847
+274
+1659
+1773
+1960
+1772
+1674
+1809
+1568
+1978
+1952
+1947
+1976
+1953
+1961
+1937
+1932
+1781
+2007
+1941
+1393
+1573
+1745
+169
+89
+1408
+1974
+1810
+1979
+1967
+890
+1958
+1930
+1954
+1759
+720
+1936
+1576
+1407
+2004
+1964
+1462
+1875
+1943
+1938
+2006
+1739
+1378
+1922
+1924
+2003
+1792
+1985
+1729
+1966
+1355
+1940
+1928
+1357
+1955
+1896
+1115
+1836
+1971
+1329
+1807
+1997
+1359
+1801
+1933
+1965
+1981
+1711
+1905
+1625
+1968
diff --git a/src/2020/mod.rs b/src/2020/mod.rs
new file mode 100644
index 0000000..87c213b
--- /dev/null
+++ b/src/2020/mod.rs
@@ -0,0 +1,33 @@
+use anyhow::Context as _;
+use std::io::BufRead as _;
+
+pub fn run(day: u8, puzzle: u8) -> anyhow::Result<()> {
+ match (day, puzzle) {
+ (1, 1) => report_repair(),
+ _ => Err(anyhow::anyhow!("unknown puzzle {}-{}", day, puzzle)),
+ }
+}
+
+fn report_repair() -> anyhow::Result<()> {
+ let f = std::fs::File::open("data/1-1.txt")
+ .context("couldn't find data file")?;
+ let f = std::io::BufReader::new(f);
+ let ints: anyhow::Result<Vec<i32>> = f
+ .lines()
+ .map(|l| {
+ l.context("failed to read a line")?
+ .parse()
+ .context("failed to parse line into an integer")
+ })
+ .collect();
+ let ints = ints?;
+ for i in &ints {
+ for j in &ints {
+ if i + j == 2020 {
+ println!("{} + {} = {}", i, j, i * j);
+ return Ok(());
+ }
+ }
+ }
+ Err(anyhow::anyhow!("no numbers summing to 2020 found"))
+}
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..b8677cb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,23 @@
-fn main() {
- println!("Hello, world!");
+#[path = "2020/mod.rs"]
+mod year2020;
+
+#[derive(Debug, structopt::StructOpt)]
+#[structopt(about = "Advent of Code")]
+enum Opt {
+ #[structopt(name = "2020")]
+ Year2020 { day: u8, puzzle: u8 },
+}
+
+#[paw::main]
+fn main(opt: Opt) {
+ let res = match opt {
+ Opt::Year2020 { day, puzzle } => crate::year2020::run(day, puzzle),
+ };
+ match res {
+ Ok(()) => {}
+ Err(e) => {
+ eprintln!("{}", e);
+ std::process::exit(1);
+ }
+ }
}