• 30 Posts
  • 122 Comments
Joined 3 years ago
cake
Cake day: July 3rd, 2023

help-circle






  • It might be lime or calcium. The German word is Kalk, but it’s basically the hard water, as you say. Yes, we were doing exactly that (the water is very hard here), and tried to remove the aerator in order to clean that too, which we hadn’t done before, and that’s how it all broke.

    I’ve now made progress in breaking off another piece, but we’re getting closer to just calling a plumber.








  • cabhantoHistory Memes@piefed.socialSmart move
    link
    fedilink
    arrow-up
    2
    ·
    3 months ago

    Honest question: how were race horses transported in the past? I assume you wouldn’t want them pulling a coach, even if they could, and riding them to a race could tire them out or risk injury?

    Are there old “horse trailers” that would be pulled by coach horses?






  • cabhantoAsk Lemmy@lemmy.world*Permanently Deleted*
    link
    fedilink
    arrow-up
    28
    arrow-down
    1
    ·
    4 months ago

    Meat. I’m vegetarian, my wife is not. When we go out to eat, if she orders meat, there’s a good chance the meat dish will get put in front of me.

    We were at a Christmas market on the weekend, and one booth had a sign that said “Make your husband happy”, and it was of course a butcher stand.


  • I believe learning languages is generally a net good. But to answer your question, it would help to know: why do you want to learn Russian?

    If you just find the idea of the language interesting, then yes! Start leaning it. If you have motivation, that will help.

    Is there specific media you’re looking to consume in its original language, Russian? Then yes, absolutely :).

    Are you just trying to learn “any Slavic language”, to extend the language families you have knowledge of? You already have some Polish, so what is it about Russian that attracts you? Is there another language that might have more resonance or utility for you?

    As far as I am aware, mostly sue to Soviet influence, Russian is probably the most-widely-understood Slavic language, so this does offer some advantages. I have spoken with Ukranians and Georgians who now don’t like speaking Russian, for obvious reasons, though I don’t know how widespread this feeling really is. And at least here in Germany, I feel like Croatian, Czech, or Slovakian would be a more useful day-to-day or holiday language, but itball depends on your goals.

    And, as a dentist once told me in regards to dental floss, but it applies here too: The best language to learn is the one that you will actually learn. If there’s a language you’ll actually stick with, that’s good.




  • Rust

    Part 1 was very straight forward. I overcomplicated it a bit by using an actual graph library, but I’m used to using it.

    I originally tried to brute force Part 2, which of course failed. I then reverted to dynamic programming, which worked well.

    use std::collections::{HashMap, VecDeque};
    
    use graphrs::{Graph, GraphSpecs};
    
    use crate::solver::DaySolver;
    
    pub struct Day11Solver;
    
    impl DaySolver for Day11Solver {
        fn part1(&self, input: String) -> String {
            let mut graph: Graph<String, ()> = Graph::new(GraphSpecs::directed_create_missing());
            let edges = input.lines()
                .flat_map(|line| {
                    let (start, end_str) = line.split_once(": ").unwrap();
                    end_str.split_whitespace()
                        .map(|end| (start.to_string(), end.to_string()))
                })
                .collect();
            graph.add_edge_tuples(edges).unwrap();
    
            let mut frontier = VecDeque::from([vec!["you".to_string()]]);
    
            let mut path_count = 0;
    
            while let Some(path) = frontier.pop_front() {
                let last = path.last().unwrap();
    
                if last == "out" {
                    path_count += 1;
                } else {
                    graph
                        .get_successor_node_names(last.to_string())
                        .unwrap()
                        .into_iter()
                        .filter(|next| !path.contains(next))
                        .map(|next| {
                            let mut new_path = path.clone();
                            new_path.push(next.clone());
                            new_path
                        })
                        .for_each(|new_path| frontier.push_back(new_path));
                }
            }
    
            path_count.to_string()
        }
    
        fn part2(&self, input: String) -> String {
            let mut graph: Graph<String, ()> = Graph::new(GraphSpecs::directed_create_missing());
            let edges = input.lines()
                .flat_map(|line| {
                    let (start, end_str) = line.split_once(": ").unwrap();
                    end_str.split_whitespace()
                        .map(|end| (start.to_string(), end.to_string()))
                })
                .collect();
            graph.add_edge_tuples(edges).unwrap();
    
            how_many_paths(
                &mut HashMap::new(),
                &graph,
                ("svr".to_string(), false, false),
            )
                .to_string()
    
        }
    }
    
    fn how_many_paths(
        cache: &mut HashMap<(String, bool, bool), usize>,
        graph: &Graph<String, ()>,
        current: (String, bool, bool),
    ) -> usize {
        if let Some(&c) = cache.get(&current) {
            c
        } else {
            let (node, has_dac, has_fft) = &current;
            if node == "out" {
                let count = if *has_dac && *has_fft { 1 } else { 0 };
                cache.insert(current, count);
                count
            } else {
                let count = graph
                    .get_successor_node_names(node.clone())
                    .unwrap()
                    .into_iter()
                    .map(|next| {
                        let next_state = (next.to_string(), *has_dac || next == "dac", *has_fft || next == "fft");
                        how_many_paths(cache, graph, next_state)
                    })
                    .sum();
                cache.insert(current, count);
                count
            }
        }
    }
    
    #[cfg(test)]
    mod tests {
        use super::*;
    
        #[test]
        fn part1() {
            let input = include_str!("../../inputs/test/11");
    
            let solver = Day11Solver {};
            assert_eq!("5", solver.part1(input.to_string()));
        }
    
        #[test]
        fn part2() {
            let input = include_str!("../../inputs/test/11-2");
    
            let solver = Day11Solver {};
            assert_eq!("2", solver.part2(input.to_string()));
        }
    }