I like that it you can actually compost it at home... but the warping is crazy. 1-2cm wide brim makes the prints stick well enough on a satin sheet. AllPHA 200C/20C on an MK4s
I grew up with xterm and can still remember switching to rxvt-unicode to finally get UTF-8 support (The distro I was using back then made the switch to all UTF-8).
Konsole is fine for me: It just works
My rule of thumb for error handling: try to avoid unwrap. Use expect with a nice error message. And only use expect for stuff that should never fail. And bubbling up the errors to the top with ? is also useful.
Well, I really tried to daily drive the Freerunner, but it was just not there: unstable software paired with unfinished buggy hardware.
Im still grateful for the project. It was my gateway to a professional career in embedded linux development.
Used a sorted/unsorted comparison to solve the first part, the second part was just filling out the else branch.
use std::{
cmp::Ordering,
collections::HashMap,
io::{BufRead, BufReader},
};
fn main() {
let mut lines = BufReader::new(std::fs::File::open("input.txt").unwrap()).lines();
let mut rules: HashMap<u64, Vec<u64>> = HashMap::default();
for line in lines.by_ref() {
let line = line.unwrap();
if line.is_empty() {
break;
}
let lr = line
.split('|')
.map(|el| el.parse::<u64>())
.collect::<Result<Vec<u64>, _>>()
.unwrap();
let left = lr[0];
let right = lr[1];
if let Some(values) = rules.get_mut(&left) {
values.push(right);
values.sort();
} else {
rules.insert(left, vec![right]);
}
}
let mut updates: Vec<Vec<u64>> = Vec::default();
for line in lines {
let line = line.unwrap();
let update = line
.split(',')
.map(|el| el.parse::<u64>())
.collect::<Result<Vec<u64>, _>>()
.unwrap();
updates.push(update);
}
let mut middle_sum = 0;
let mut fixed_middle_sum = 0;
for update in updates {
let mut update_sorted = update.clone();
update_sorted.sort_by(|a, b| {
if let Some(rules) = rules.get(a) {
if rules.contains(b) {
Ordering::Less
} else {
Ordering::Equal
}
} else {
Ordering::Equal
}
});
if update.eq(&update_sorted) {
let middle = update[(update.len() - 1) / 2];
middle_sum += middle;
} else {
let middle = update_sorted[(update_sorted.len() - 1) / 2];
fixed_middle_sum += middle;
}
}
println!("part1: {} part2: {}", middle_sum, fixed_middle_sum);
}
Decided to give it a go with the nom parser (first time using this crate). Turned out quite nicely. Had some issues with the alt combinator: All alternatives have to return the same type, using a enum to wrap all options did the trick.
I like that it you can actually compost it at home... but the warping is crazy. 1-2cm wide brim makes the prints stick well enough on a satin sheet. AllPHA 200C/20C on an MK4s
I grew up with xterm and can still remember switching to rxvt-unicode to finally get UTF-8 support (The distro I was using back then made the switch to all UTF-8). Konsole is fine for me: It just works
This is so adorable, I want to upvote it twice!
Nice project, I really like the minimal design!
I also experienced a panic on image load.
My rule of thumb for error handling: try to avoid unwrap. Use expect with a nice error message. And only use expect for stuff that should never fail. And bubbling up the errors to the top with
?is also useful.Well, I really tried to daily drive the Freerunner, but it was just not there: unstable software paired with unfinished buggy hardware. Im still grateful for the project. It was my gateway to a professional career in embedded linux development.
Rust
Used a sorted/unsorted comparison to solve the first part, the second part was just filling out the else branch.
Rust with nom parser
Decided to give it a go with the nom parser (first time using this crate). Turned out quite nicely. Had some issues with the alt combinator: All alternatives have to return the same type, using a enum to wrap all options did the trick.
Thanks for creating and sharing this tool! Will definitely add it to my toolbelt!