mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-12-24 00:56:25 +00:00
Compare commits
No commits in common. "796033f6b3876e6335d1cfc29d800b10f8719aa6" and "14d00e16d51b89ce1b2e8f548a9624b18a3a40cc" have entirely different histories.
796033f6b3
...
14d00e16d5
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,7 +2,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
*.txt
|
*.txt
|
||||||
.env*
|
.env*
|
||||||
|
|
||||||
|
|
||||||
# Added by cargo
|
|
||||||
/target
|
|
||||||
|
@ -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
7
Cargo.lock
generated
@ -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"
|
|
13
Cargo.toml
13
Cargo.toml
@ -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
|
|
38
README.md
38
README.md
@ -1,37 +1,5 @@
|
|||||||
# Advent Of Code
|
# Advent Of Code
|
||||||
|
|
||||||
## Getting started
|
> New days are generated with [`hygen`](https://github.com/jondot/hygen).
|
||||||
|
>
|
||||||
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
|
> `hygen riddle new --year 2021 --day 01`
|
||||||
|
|
||||||
```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.
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
---
|
|
||||||
inject: true
|
|
||||||
to: cargo.toml
|
|
||||||
before: "# INJECT HERE"
|
|
||||||
skip_if: <%= id %>
|
|
||||||
---
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "<%= id %>"
|
|
||||||
path = "<%= dir %>/rust/main.rs"
|
|
@ -12,13 +12,6 @@ async function getInput(year, day) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
params: async ({ args }) => {
|
params: async ({ args }) => {
|
||||||
const day = args.day.toString().padStart(2, '0') // Padded
|
return { ...args, input: await getInput(args.year, args.day) }
|
||||||
return {
|
|
||||||
...args,
|
|
||||||
id: `${args.year}-${day}`,
|
|
||||||
dir: `./${args.year}/${day}`,
|
|
||||||
input: await getInput(args.year, parseInt(day)),
|
|
||||||
day,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
to: <%= dir %>/input.txt
|
to: <%= year %>/<%= day %>/input.txt
|
||||||
unless_exists: true
|
unless_exists: true
|
||||||
---
|
---
|
||||||
<%= input %>
|
<%= input %>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
to: <%= dir %>/python/main.py
|
to: <%= year %>/<%= day %>/python/main.py
|
||||||
unless_exists: true
|
unless_exists: true
|
||||||
---
|
---
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
to: <%= dir %>/README.md
|
to: <%= year %>/<%= day %>/README.md
|
||||||
unless_exists: true
|
unless_exists: true
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -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();
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
---
|
---
|
||||||
to: <%= dir %>/test.txt
|
to: <%= year %>/<%= day %>/test.txt
|
||||||
unless_exists: true
|
unless_exists: true
|
||||||
---
|
---
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
{
|
{
|
||||||
"scripts": {
|
|
||||||
"gen": "bun hygen riddle new"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.6.0",
|
"axios": "^1.6.0",
|
||||||
"hygen": "^6.2.11"
|
"hygen": "^6.2.11"
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
[toolchain]
|
|
||||||
channel = "nightly"
|
|
Loading…
Reference in New Issue
Block a user