Advent of Code Day 2 in Rust
https://gitlab.com/MisterBiggs/aoc_2022-rust/-/blob/master/src/day2.rs
```rust
use itertools::Itertools;
use std::fs;
pub fn run() {
println!("Day 2:");
let input = fs::read_to_string("./inputs/day2.txt").expect("Could not read file");
println!("\tPart 1: {}", part1(&input));
println!("\tPart 2: {}", part2(&input));
}
#[derive(PartialEq, Clone, Copy)]
enum Hand {
Rock = 1,
Paper,
Scissors,
}
#[derive(Clone, Copy)]
enum Outcome {
Lost = 0,
Draw = 3,
Win = 6,
}
fn part1(input: &str) -> usize {
input
.trim()
.split('\n')
.map(|round_str| {
let round = round_str.split_once(' ').unwrap();
let opponent = match round.0 {
"A" => Hand::Rock,
"B" => Hand::Paper,
"C" => Hand::Scissors,
_ => panic!(),
};
let me = match round.1 {
"X" => Hand::Rock,
"Y" => Hand::Paper,
"Z" => Hand::Scissors,
_ => panic!(),
};
let outcome = match (opponent, me) {
(l, r) if l == r => Outcome::Draw,
(Hand::Rock, Hand::Paper) => Outcome::Win,
(Hand::Paper, Hand::Scissors) => Outcome::Win,
(Hand::Scissors, Hand::Rock) => Outcome::Win,
_ => Outcome::Lost,
};
outcome as usize + me as usize
})
.sum()
}
fn part2(input: &str) -> usize {
input
.trim()
.split('\n')
.map(|round_str| {
let round = round_str.split_once(' ').unwrap();
let opponent = match round.0 {
"A" => Hand::Rock,
"B" => Hand::Paper,
"C" => Hand::Scissors,
_ => panic!(),
};
let outcome = match round.1 {
"X" => Outcome::Lost,
"Y" => Outcome::Draw,
"Z" => Outcome::Win,
_ => panic!(),
};
let me = match (outcome, opponent) {
(Outcome::Draw, _) => opponent,
(Outcome::Win, Hand::Rock) => Hand::Paper,
(Outcome::Win, Hand::Paper) => Hand::Scissors,
(Outcome::Win, Hand::Scissors) => Hand::Rock,
(Outcome::Lost, Hand::Rock) => Hand::Scissors,
(Outcome::Lost, Hand::Paper) => Hand::Rock,
(Outcome::Lost, Hand::Scissors) => Hand::Paper,
};
outcome as usize + me as usize
})
.sum()
}
```
Advent of code day 1 in rust
https://gitlab.com/MisterBiggs/aoc_2022-rust/-/blob/master/src/day1.rs
```rust
fn part1(food_input: &str) -> usize {
food_input
.split("\n\n")
.collect::<Vec<&str>>()
.into_iter()
.map(|elf| {
elf.split_whitespace()
.map(|food| food.parse::<usize>().unwrap())
.sum()
})
.collect::<Vec<usize>>()
.into_iter()
.max()
.unwrap()
}
```
```rs
fn part2(food_input: &str) -> usize {
let mut elves_calories = food_input
.split("\n\n")
.collect::<Vec<&str>>()
.into_iter()
.map(|elf| {
elf.split_whitespace()
.map(|food| food.parse::<usize>().unwrap())
.sum()
})
.collect::<Vec<usize>>();
elves_calories.sort_by(|l, r| r.cmp(l));
elves_calories[..3].iter().sum::<usize>()
}
```
The amount of work it takes to maintain header files in #cpp is honestly absurd
Any #googlefi users out there notice service has been steadily degrading?
ATTENTION EVERYONE WRINGING THEIR HANDS OVER “#MASTODON ADMINS CAN READ MY DIRECT MESSAGES”: #SysAdmins have *always* been able to read your #email and DMs unless encrypted, including at the big #SocialNetworks and Internet providers. We used to have t-shirts that said, “I READ YOUR EMAIL.”
It’s just hitting now because you got used to places where the admins were kept away in their cubicles and data centers instead of greeting you at the front door.
Interested in the automated discovery of physical equations from data? Check out Julius's talk on DataDrivenDiffeq: a #julialang #sciml #symbolicregression #SymbolicAI package which lets you give time series data and returns the equations which generated the data. It even generates the LaTeX!
Somewhere, someone finally made this and I think it's beautiful: https://www.thingiverse.com/thing:4687836
I'm Commander Shepard, and This Is My Favorite Day on the Citadel to Celebrate the 15th Anniversary of Mass Effect.
Art by Matt Rhodes (early Prothean) & Derek Watts (early Citadel)
#Masseffect #scifi #Normandy #games #conceptart #bioware
Sure is a drag writing going back C at work after writing #rustlang all weekend
A few recommendations for life on Mastodon:
1) Follow anyone you think looks potentially interesting; you can always unfollow later, and they may lead you to new people via boosted posts.
2) Boost posts you think are worthy, so others can discover new content.
3) Don't obsess on replicating your Twitter follows on Mastodon; let it be its own experience, and grow it organically. Obvs follow anyone you miss from Twitter, but this isn't a 1:1 replacement; have fun, follow your instincts.
#sls please I'm getting sleepy
Software Engineer working on space stuff at Blue Origin he/him