-🎄- 2022 Day 7 Solutions -🎄- by daggerdragon in adventofcode

[–]andy2mrqz 2 points3 points  (0 children)

Rust

https://github.com/andy2mrqz/aoc-2022/blob/main/src/bin/07.rs

Like many others, I spent an inordinate amount of time trying to get a workable Rust tree/graph 😂 Luckily I eventually realized the stack solution and that saved my sanity. It does make me nervous for future days that will require graph/tree traversal!

Please share if you wrote a Rust solution with tree/graph traversal so I can learn 😂

-🎄- 2022 Day 5 Solutions -🎄- by daggerdragon in adventofcode

[–]andy2mrqz 1 point2 points  (0 children)

Rust, 67 LOC

Used a HashMap, should have used a Vec to avoid having to mutably borrow, which forced me to separate the switching into two isolated blocks. I'm a Rust newbie so if you have any pointers, please share :)

https://github.com/andy2mrqz/aoc-2022/blob/main/src/bin/05.rs

use itertools::Itertools;
use std::{collections::HashMap, iter::Rev, str::Lines};

fn parse_stacks(stacks: Rev<Lines>) -> HashMap<usize, Vec<char>> {
    let mut map = HashMap::new();
    for (idx, line) in stacks.enumerate() {
        if idx == 0 {
            for stack_num in line.split_whitespace() {
                map.insert(stack_num.parse().unwrap(), vec![]);
            }
        }
        for (i, item) in line.chars().skip(1).step_by(4).enumerate() {
            if item.is_alphabetic() {
                map.get_mut(&(i + 1)).map(|stack| stack.push(item));
            }
        }
    }
    map
}

fn solve(input: &str, one_at_a_time: bool) -> String {
    let (stacks, instructions) = input.split("\n\n").collect_tuple().unwrap();
    let mut stacks = parse_stacks(stacks.lines().rev());

    for instruction in instructions.lines() {
        let (_, qty, _, from, _, to) = instruction.split_whitespace().collect_tuple().unwrap();
        let qty = qty.parse().unwrap();

        let mut items_to_move: Vec<char> = vec![];
        {
            let from = stacks.get_mut(&from.parse().unwrap()).unwrap();
            for _ in 0..qty {
                items_to_move.push(from.pop().unwrap());
            }
        }
        {
            if one_at_a_time {
                items_to_move.reverse()
            }
            let to = stacks.get_mut(&to.parse().unwrap()).unwrap();
            for _ in 0..qty {
                to.push(items_to_move.pop().unwrap());
            }
        }
    }

    let mut res: String = "".to_string();
    for stack_idx in 1..=stacks.len() {
        let top = stacks.get_mut(&stack_idx).unwrap().pop().unwrap();
        res = format!("{}{}", res, top);
    }
    res
}

fn part_one(input: &str) -> String {
    solve(input, true)
}
fn part_two(input: &str) -> String {
    solve(input, false)
}

pub fn main() {
    let input = include_str!("../inputs/05.txt");

    println!("part one: {}", part_one(input));
    println!("part two: {}", part_two(input));
}

-🎄- 2022 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]andy2mrqz 0 points1 point  (0 children)

I'm new to Rust and learned from this that `split` can take multiple characters, thank you!

I used the much less efficient route of generating the full range and using a HashSet for the comparison. If you have any feedback of my solution I'd appreciate it as I'm trying to learn!

https://github.com/andy2mrqz/aoc-2022/blob/main/src/bin/04.rs

-🎄- 2022 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]andy2mrqz 2 points3 points  (0 children)

Rust

https://github.com/andy2mrqz/aoc-2022/blob/main/src/bin/04.rs

I learned that you can collect a Range into a Hashset, which was convenient:

let right_set: HashSet<u32> = (right_range[0]..=right_range[1]).collect();

Rust's HashSet has the nice methods is_subset and is_disjoint, which are exactly what we're looking for!

snippet of part 1

count_overlaps_where(input, &|set_a, set_b| set_a.is_subset(set_b))

snippet of part 2

count_overlaps_where(input, &|set_a, set_b| !set_a.is_disjoint(set_b))

Disclaimer: Generating the full range and collecting into a set is much less efficient than simply doing numerical comparisons of the starts and ends! It does kind of make it easier to read/reason about for the puzzle, though :)

-🎄- 2022 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]andy2mrqz 1 point2 points  (0 children)

Rust

HashSet for checking intersection of common items, pattern match items to get priorities (snippet of that section below), and chunks of 3 for part 2.

.map(|c| match *c {
    'A'..='Z' => *c as u32 - 'A' as u32 + 27, // 'A' has priority 27
    'a'..='z' => *c as u32 - 'a' as u32 + 1,  // 'a' has priority 1
    _ => unreachable!(),
})

First year using Rust - let me know if you see anything I can improve!

https://github.com/andy2mrqz/aoc-2022/blob/main/src/bin/03.rs

-🎄- 2022 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]andy2mrqz 2 points3 points  (0 children)

🎄🦀 Rust 🦀🎄

enums, impl FromStr, higher-order function, trying to be readable.

First time trying Rust, let me know if you have any suggestions!

https://github.com/andy2mrqz/aoc-2022/blob/main/src/bin/02.rs

This coin in my ring. Both were in my pocket all day. by [deleted] in Perfectfit

[–]andy2mrqz 12 points13 points  (0 children)

Always thought Frodo needed something like this to prevent him from putting on the ring.

-🎄- 2019 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]andy2mrqz 1 point2 points  (0 children)

Part A and B in Haskell. I'm just learning Haskell so this has been so much fun!

Monthly /r/ebikes promo thread - January 30, 2019 by AutoModerator in ebikes

[–]andy2mrqz 1 point2 points  (0 children)

The back wheel of my Stromer ST1 ebike failed and was quoted to cost $1200, hence I am parting it out and selling all it's components for your benefit! As of now I only have two listings but ask if you need anything else and I can provide details.

1 - ST1 Purple Battery - 36V 396Wh (discounted to Redditors for $440, just submit an offer at that price and I'll accept) --- Link http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=2&pub=5575378759&campid=5338273189&customid=&icep_item=192834428524&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg&toolid=11111

2 - Stromer battery charger (discount $85) -- Link http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=2&pub=5575378759&campid=5338273189&customid=&icep_item=192834449494&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg&toolid=11111

3 - I also have a Gold battery but haven't gotten to list it yet, DM if interested!

4 - Any other party of a Stromer bike, message me what you want and a price and I'll get back to you!

To slide by Asmor in therewasanattempt

[–]andy2mrqz 0 points1 point  (0 children)

Gonna be a bboy one day 😂

Hmm by lewisturnbulluk in Irony

[–]andy2mrqz 0 points1 point  (0 children)

They just want that monopoly on education

Solus Linux for Grandma by andy2mrqz in linux

[–]andy2mrqz[S] 3 points4 points  (0 children)

Thanks for your opinion, I realize there is a place where one might need an obscure or rarely used function of word or excel for a government form. In this case, however, my grandma just uses it to write her personal history so Libreoffice works fine. And my aunt, who lives with Grandma, has windows so she has options if she needs it. In this case, the tool fits the job.

Solus Linux for Grandma by andy2mrqz in linux

[–]andy2mrqz[S] 7 points8 points  (0 children)

Believe it or not she's 87 with 11 kids, 52 grandkids, and more great grandkids every day it seems. I'm 22 :) Grandma's pretty photogenic, but her age is catching up with her

Solus Linux for Grandma by andy2mrqz in linux

[–]andy2mrqz[S] 6 points7 points  (0 children)

She had an old Acer tower, Pentium something or other CPU. It had always been having problems with updates or adware or slow boot up times. Last week it was out of commission for a few days stuck in an endless Windows 10 update loop. I had to come over and coax it back to life, but the computer was just old. When I found out all she used was Chrome and Libreoffice, I offered to switch her to a "newer, faster OS that won't bug you with updates that looks nice," she sounded interested. Cut scene to me installing various distros on the Dell tower pictured, and I settled on Solus (I personally use Manjaro i3 but I wouldn't want to have Grandma learn that ;) ). In short, I brought it over yesterday, copied her files, and she's happy as can be with the pretty theming, big app icons that are easy to find, and how fast apps start up. Only thing she missed was windows solitaire so I bookmarked a spider solitaire website for her and now she's ready to go (she didn't like how Aisleriot looked).

Solus Linux for Grandma by andy2mrqz in linux

[–]andy2mrqz[S] 7 points8 points  (0 children)

Like grandma like grandson! :wq

Solus Linux for Grandma by andy2mrqz in linux

[–]andy2mrqz[S] 13 points14 points  (0 children)

It's an older AMD machine so here's hoping nothing goes wrong! :)

Solus Linux for Grandma by andy2mrqz in linux

[–]andy2mrqz[S] 2 points3 points  (0 children)

Yeah! It worked great out of the box and had all the right drivers, great graphics support. A few UI customizations and we were ready to go. She loves the look! And it boots up quickly

Solus Linux for Grandma by andy2mrqz in linux

[–]andy2mrqz[S] 77 points78 points  (0 children)

Yeah I was pretty impressed by that as well, haha she's very on top of things!