Compare commits

..

No commits in common. "796033f6b3876e6335d1cfc29d800b10f8719aa6" and "14d00e16d51b89ce1b2e8f548a9624b18a3a40cc" have entirely different histories.

14 changed files with 8 additions and 169 deletions

4
.gitignore vendored
View File

@ -2,7 +2,3 @@
node_modules
*.txt
.env*
# Added by cargo
/target

View File

@ -1,45 +0,0 @@
#![feature(test)]
extern crate test;
#[cfg(test)]
mod tests {
use super::*;
use test::Bencher;
#[bench]
fn bench_a(b: &mut Bencher) {
b.iter(|| part_a());
}
#[bench]
fn bench_b(b: &mut Bencher) {
b.iter(|| part_b());
}
}
fn part_a() {
let result: u32 = include_str!("../input.txt")
.trim()
.split("\n\n")
.map(|x| x.lines().map(|x| x.parse::<u32>().unwrap()).sum())
.max()
.unwrap();
println!("A: {}", result);
}
fn part_b() {
let mut result = include_str!("../input.txt")
.trim()
.split("\n\n")
.map(|x| x.lines().map(|x| x.parse::<u32>().unwrap()).sum::<u32>())
.collect::<Vec<u32>>();
result.sort_unstable();
let total = result.into_iter().rev().take(3).sum::<u32>();
println!("B: {}", total);
}
fn main() {
part_a();
part_b();
}

7
Cargo.lock generated
View File

@ -1,7 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "advent-of-code"
version = "0.1.0"

View File

@ -1,13 +0,0 @@
[package]
name = "advent-of-code"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "2022-01"
path = "./2022/01/rust/main.rs"
# INJECT HERE

View File

@ -1,37 +1,5 @@
# Advent Of Code
## Getting started
New "days" are generated with [`hygen`](https://github.com/jondot/hygen). This will bootstrap code for python and rust. See details about the specifica languages below
```bash
# First time setup
bun i
# Generate
bun run gen --year 2022 --day 1
```
## Python
## Rust
Run a single day:
```bash
cargo run --bin 2022-01
```
Bench a day:
```bash
cargo bench --bin 2022-01
```
Bench all days:
```bash
cargo bench
```
> The benchmark is the built in Rust one. This is the [reason](https://doc.rust-lang.org/cargo/commands/cargo-bench.html) for the _nightly_ version.
> New days are generated with [`hygen`](https://github.com/jondot/hygen).
>
> `hygen riddle new --year 2021 --day 01`

View File

@ -1,10 +0,0 @@
---
inject: true
to: cargo.toml
before: "# INJECT HERE"
skip_if: <%= id %>
---
[[bin]]
name = "<%= id %>"
path = "<%= dir %>/rust/main.rs"

View File

@ -12,13 +12,6 @@ async function getInput(year, day) {
module.exports = {
params: async ({ args }) => {
const day = args.day.toString().padStart(2, '0') // Padded
return {
...args,
id: `${args.year}-${day}`,
dir: `./${args.year}/${day}`,
input: await getInput(args.year, parseInt(day)),
day,
}
return { ...args, input: await getInput(args.year, args.day) }
},
}

View File

@ -1,5 +1,5 @@
---
to: <%= dir %>/input.txt
to: <%= year %>/<%= day %>/input.txt
unless_exists: true
---
<%= input %>

View File

@ -1,5 +1,5 @@
---
to: <%= dir %>/python/main.py
to: <%= year %>/<%= day %>/python/main.py
unless_exists: true
---
#!/usr/bin/env python

View File

@ -1,5 +1,5 @@
---
to: <%= dir %>/README.md
to: <%= year %>/<%= day %>/README.md
unless_exists: true
---

View File

@ -1,38 +0,0 @@
---
to: <%= dir %>/rust/main.rs
unless_exists: true
---
#![feature(test)]
extern crate test;
#[cfg(test)]
mod tests {
use super::*;
use test::Bencher;
#[bench]
fn bench_a(b: &mut Bencher) {
b.iter(|| part_a());
}
#[bench]
fn bench_b(b: &mut Bencher) {
b.iter(|| part_b());
}
}
fn part_a() {
let result = include_str!("../input.txt");
println!("A: {}", result);
}
fn part_b() {
let result = include_str!("../input.txt");
println!("A: {}", result);
}
fn main() {
part_a();
part_b();
}

View File

@ -1,4 +1,4 @@
---
to: <%= dir %>/test.txt
to: <%= year %>/<%= day %>/test.txt
unless_exists: true
---

View File

@ -1,7 +1,4 @@
{
"scripts": {
"gen": "bun hygen riddle new"
},
"dependencies": {
"axios": "^1.6.0",
"hygen": "^6.2.11"

View File

@ -1,2 +0,0 @@
[toolchain]
channel = "nightly"