Compare commits

...

2 commits

Author SHA1 Message Date
Antoine Martin 0df2dd8dd8 2023: day01: part 1 2023-12-02 14:24:43 +01:00
Antoine Martin 516fed49be flake.lock: Update
Flake lock file updates:

• Updated input 'flake-utils':
    'github:numtide/flake-utils/5aed5285a952e0b949eb3ba02c12fa4fcfef535f' (2022-11-02)
  → 'github:numtide/flake-utils/ff7b65b44d01cf9ba6a71320833626af21126384' (2023-09-12)
• Added input 'flake-utils/systems':
    'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e' (2023-04-09)
• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/18823e511bc85ed27bfabe33cccecb389f9aa92d' (2022-12-05)
  → 'github:oxalica/rust-overlay/47fe4578cb64a365f400e682a70e054657c42fa5' (2023-12-02)
• Updated input 'rust-overlay/flake-utils':
    'github:numtide/flake-utils/c0e246b9b83f637f4681389ecabcb2681b4f3af0' (2022-08-07)
  → 'github:numtide/flake-utils/cfacdce06f30d2b68473a46042957675eebb3401' (2023-04-11)
• Added input 'rust-overlay/flake-utils/systems':
    'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e' (2023-04-09)
• Updated input 'rust-overlay/nixpkgs':
    'github:NixOS/nixpkgs/14ccaaedd95a488dd7ae142757884d8e125b3363' (2022-10-09)
  → 'github:NixOS/nixpkgs/96ba1c52e54e74c3197f4d43026b3f3d92e83ff9' (2023-04-13)
2023-12-02 14:06:00 +01:00
10 changed files with 1152 additions and 18 deletions

9
Cargo.lock generated
View file

@ -115,6 +115,15 @@ dependencies = [
"criterion 0.4.0",
]
[[package]]
name = "aoc2023"
version = "0.1.0"
dependencies = [
"anyhow",
"aoc",
"criterion 0.4.0",
]
[[package]]
name = "atty"
version = "0.2.14"

View file

@ -1,7 +1,9 @@
[workspace]
members = ["aoc20*", "aoc20*/aoc20*_bench"]
default-members = ["aoc2022"]
default-members = ["aoc2023"]
resolver = "2"
[profile.release]
debug = true

21
aoc2023/Cargo.toml Normal file
View file

@ -0,0 +1,21 @@
[package]
name = "aoc2023"
version = "0.1.0"
authors = ["Antoine Martin <antoine@alarsyo.net>"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
aoc = { path = "../aoc" }
anyhow = "1.0"
[dev-dependencies]
criterion = { version = "0.4", default-features = false, features = [ "rayon" ] }
[lib]
path = "src/lib.rs"
[[bin]]
name = "aoc2023"
path = "src/main.rs"

1000
aoc2023/input/day01.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

50
aoc2023/src/day01.rs Normal file
View file

@ -0,0 +1,50 @@
use std::fmt::Write;
use anyhow::Result;
const INPUT: &str = include_str!("../input/day01.txt");
pub fn run() -> Result<String> {
let mut res = String::with_capacity(128);
writeln!(res, "part 1: {}", part1(INPUT)?)?;
writeln!(res, "part 2: {}", part2(INPUT)?)?;
Ok(res)
}
fn part1(input: &str) -> Result<u64> {
let digit_list = input
.lines()
.map(|s| s.chars().filter(char::is_ascii_digit).collect::<String>());
Ok(digit_list
.map(|digits| {
let first = digits.chars().next().unwrap().to_digit(10).unwrap() as u64;
let last = digits.chars().last().unwrap().to_digit(10).unwrap() as u64;
first * 10 + last
})
.sum())
}
fn part2(input: &str) -> Result<u64> {
todo!()
}
#[cfg(test)]
mod tests {
use super::*;
const PROVIDED: &str = include_str!("../input/day01_provided.txt");
#[test]
fn part1_provided() {
assert_eq!(part1(PROVIDED).unwrap(), 142);
}
#[test]
fn part1_real() {
assert_eq!(part1(INPUT).unwrap(), 54697);
}
}

1
aoc2023/src/lib.rs Normal file
View file

@ -0,0 +1 @@
pub mod day01;

11
aoc2023/src/main.rs Normal file
View file

@ -0,0 +1,11 @@
use anyhow::Result;
use aoc::DayFunc;
use aoc2023::day01;
fn main() -> Result<()> {
let days: &[DayFunc] = &[day01::run];
aoc::run(days)
}

View file

@ -1,12 +1,15 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
@ -16,12 +19,15 @@
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"type": "github"
},
"original": {
@ -32,27 +38,27 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1669834992,
"narHash": "sha256-YnhZGHgb4C3Q7DSGisO/stc50jFb9F/MzHeKS4giotg=",
"lastModified": 1701389149,
"narHash": "sha256-rU1suTIEd5DGCaAXKW6yHoCfR1mnYjOXQFOaH7M23js=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "596a8e828c5dfa504f91918d0fa4152db3ab5502",
"rev": "5de0b32be6e85dc1a9404c75131316e4ffbc634c",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-22.11",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1665296151,
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
"lastModified": 1681358109,
"narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
"rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9",
"type": "github"
},
"original": {
@ -75,11 +81,11 @@
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1670207212,
"narHash": "sha256-uuKbbv0L+QoXiqO7METP9BihY0F7hJqGdKn7xDVfyFw=",
"lastModified": 1701483183,
"narHash": "sha256-MDH3oUajqTaYClCiq1QK7jWVMtMFDJWxVBCFAnkt6J4=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "18823e511bc85ed27bfabe33cccecb389f9aa92d",
"rev": "47fe4578cb64a365f400e682a70e054657c42fa5",
"type": "github"
},
"original": {
@ -87,6 +93,36 @@
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View file

@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};