Skip to content

Instantly share code, notes, and snippets.

@ryleu
Last active December 2, 2022 07:43
Show Gist options
  • Save ryleu/db96283fd471671253801de6bbb58a22 to your computer and use it in GitHub Desktop.
Save ryleu/db96283fd471671253801de6bbb58a22 to your computer and use it in GitHub Desktop.
Advent of Code 2022—Ryleu's Soluitons

Howdy! I'm Ryleu. I love writing code, so this year I'm participating in Advent of Code!

The goal of this gist is to give people an easy place to see my solutions to the various challenges I will face this December. I plan to complete all challenges this year in Rust, though I might cave partway through and use Kotlin or Python.

While my goal is not to be the fastest or to make the fastest code, I do intend on keeping shitcode out of my solutions, so if you do happen to find something truly awful that the Rust compiler didn't catch, feel free to let me know.

BEWARE

This gist will contain spoilers for ALL Advent of Code challenges that I complete. If you continue, you should already have the problems solved!

SPOILERS

SPOILERS

SPOILERS

SPOILERS

SPOILERS

SPOILERS

SPOILERS

SPOILERS

SPOILERS

SPOILERS

fn main() {
const TOP_X: usize = 3;
let input = include_str!("input.txt");
let mut greatest: [u64; TOP_X] = [0; TOP_X];
let mut sum: u64 = 0;
for line in input.split("\n") {
if line.is_empty() {
let mut test: u64 = sum;
for i in 0..greatest.len() {
if test > greatest[i] {
let carry = greatest[i];
greatest[i] = test;
test = carry;
}
}
sum = 0;
continue;
}
sum += line.parse::<u64>().unwrap();
}
println!(
"Greatest {} amounts of calories: {:?}\nSum: {}", TOP_X, greatest, greatest.iter().sum::<u64>());
}
use std::collections::HashMap;
fn main() {
let lose = HashMap::from([
("rock", "scissors"),
("paper", "rock"),
("scissors", "paper")
]);
let win = HashMap::from([
("rock", "paper"),
("paper", "scissors"),
("scissors", "rock")
]);
let shape_points = HashMap::from([
("rock", 1),
("paper", 2),
("scissors", 3)
]);
let letters = HashMap::from([
("A", "rock"),
("B", "paper"),
("C", "scissors")
]);
let input = include_str!("input.txt").trim();
let mut score: i64 = 0;
for line in input.split("\n") {
let tools: Vec<&str> = line.split(" ").collect();
let left = letters.get(tools[0]).unwrap();
let right = tools[1];
match right {
// need to lose
"X" => {
score += shape_points[lose[left]];
}
// need to draw
"Y" => {
score += 3;
score += shape_points[left];
}
// need to win
"Z" => {
score += 6;
score += shape_points[win[left]];
}
&_ => panic!("fuck"),
}
}
println!("Score: {}", score);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment