mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-12-23 16:46:32 +00:00
Compare commits
4 Commits
14d00e16d5
...
796033f6b3
Author | SHA1 | Date | |
---|---|---|---|
796033f6b3 | |||
ad6ddf4f75 | |||
eb723f5112 | |||
3af5af2461 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,3 +2,7 @@
|
||||
node_modules
|
||||
*.txt
|
||||
.env*
|
||||
|
||||
|
||||
# Added by cargo
|
||||
/target
|
||||
|
45
2022/01/rust/main.rs
Normal file
45
2022/01/rust/main.rs
Normal file
@ -0,0 +1,45 @@
|
||||
#![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
Normal file
7
Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# 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"
|
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[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
|
38
README.md
38
README.md
@ -1,5 +1,37 @@
|
||||
# Advent Of Code
|
||||
|
||||
> New days are generated with [`hygen`](https://github.com/jondot/hygen).
|
||||
>
|
||||
> `hygen riddle new --year 2021 --day 01`
|
||||
## 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.
|
||||
|
10
_templates/riddle/new/cargo.ejs.t
Normal file
10
_templates/riddle/new/cargo.ejs.t
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
inject: true
|
||||
to: cargo.toml
|
||||
before: "# INJECT HERE"
|
||||
skip_if: <%= id %>
|
||||
---
|
||||
|
||||
[[bin]]
|
||||
name = "<%= id %>"
|
||||
path = "<%= dir %>/rust/main.rs"
|
@ -12,6 +12,13 @@ async function getInput(year, day) {
|
||||
|
||||
module.exports = {
|
||||
params: async ({ args }) => {
|
||||
return { ...args, input: await getInput(args.year, args.day) }
|
||||
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,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
to: <%= year %>/<%= day %>/input.txt
|
||||
to: <%= dir %>/input.txt
|
||||
unless_exists: true
|
||||
---
|
||||
<%= input %>
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
to: <%= year %>/<%= day %>/python/main.py
|
||||
to: <%= dir %>/python/main.py
|
||||
unless_exists: true
|
||||
---
|
||||
#!/usr/bin/env python
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
to: <%= year %>/<%= day %>/README.md
|
||||
to: <%= dir %>/README.md
|
||||
unless_exists: true
|
||||
---
|
||||
|
||||
|
38
_templates/riddle/new/rust.ejs.t
Normal file
38
_templates/riddle/new/rust.ejs.t
Normal file
@ -0,0 +1,38 @@
|
||||
---
|
||||
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();
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
---
|
||||
to: <%= year %>/<%= day %>/test.txt
|
||||
to: <%= dir %>/test.txt
|
||||
unless_exists: true
|
||||
---
|
||||
|
@ -1,4 +1,7 @@
|
||||
{
|
||||
"scripts": {
|
||||
"gen": "bun hygen riddle new"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.6.0",
|
||||
"hygen": "^6.2.11"
|
||||
|
2
rust-toolchain.toml
Normal file
2
rust-toolchain.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[toolchain]
|
||||
channel = "nightly"
|
Loading…
Reference in New Issue
Block a user