mirror of
https://gitlab.com/MisterBiggs/aoc2021.git
synced 2025-06-15 22:46:51 +00:00
pt 1
This commit is contained in:
parent
6b57a0330a
commit
3f4182acf4
9
day2/.devcontainer/Dockerfile
Normal file
9
day2/.devcontainer/Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/rust/.devcontainer/base.Dockerfile
|
||||
|
||||
# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
|
||||
ARG VARIANT="buster"
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT}
|
||||
|
||||
# [Optional] Uncomment this section to install additional packages.
|
||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
46
day2/.devcontainer/devcontainer.json
Normal file
46
day2/.devcontainer/devcontainer.json
Normal file
@ -0,0 +1,46 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/rust
|
||||
{
|
||||
"name": "Rust",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
"args": {
|
||||
// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
|
||||
// Use bullseye when on local on arm64/Apple Silicon.
|
||||
"VARIANT": "buster"
|
||||
}
|
||||
},
|
||||
"runArgs": [
|
||||
"--cap-add=SYS_PTRACE",
|
||||
"--security-opt",
|
||||
"seccomp=unconfined"
|
||||
],
|
||||
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {
|
||||
"lldb.executable": "/usr/bin/lldb",
|
||||
// VS Code don't watch files under ./target
|
||||
"files.watcherExclude": {
|
||||
"**/target/**": true
|
||||
},
|
||||
"rust-analyzer.checkOnSave.command": "clippy"
|
||||
},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"vadimcn.vscode-lldb",
|
||||
"mutantdino.resourcemonitor",
|
||||
"matklad.rust-analyzer",
|
||||
"tamasfe.even-better-toml",
|
||||
"serayuzgur.crates"
|
||||
],
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "rustc --version",
|
||||
|
||||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
||||
"remoteUser": "vscode"
|
||||
}
|
9
day2/Cargo.toml
Normal file
9
day2/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "day2"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = "1.0.130"
|
1000
day2/input.txt
Normal file
1000
day2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
8
day2/rust/Cargo.toml
Normal file
8
day2/rust/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
3
day2/rust/src/main.rs
Normal file
3
day2/rust/src/main.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
36
day2/src/main.rs
Normal file
36
day2/src/main.rs
Normal file
@ -0,0 +1,36 @@
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
let input = fs::read_to_string("./input.txt").expect("Could not read file");
|
||||
|
||||
let commands: Vec<(&str, i32)> = input
|
||||
.lines()
|
||||
.map(|s| {
|
||||
let mut split = s.split_whitespace();
|
||||
(
|
||||
split.next().unwrap(),
|
||||
split.next().unwrap().parse::<i32>().unwrap(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
part1(commands)
|
||||
}
|
||||
|
||||
fn part1(commands: Vec<(&str, i32)>) {
|
||||
let mut position = 0;
|
||||
let mut depth = 0;
|
||||
|
||||
for (dir, amt) in commands.iter().map(|a| *a) {
|
||||
let change = match dir {
|
||||
"forward" => (amt, 0),
|
||||
"up" => (0, -amt),
|
||||
"down" => (0, amt),
|
||||
_ => (0, 0),
|
||||
};
|
||||
|
||||
position += change.0;
|
||||
depth += change.1;
|
||||
}
|
||||
println!("Part 1: {}", position * depth);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user