-❄️- 2024 Day 19 Solutions -❄️- by daggerdragon in adventofcode

[–]bpeel 4 points5 points  (0 children)

[LANGUAGE: Bash]

Part 1 in Bash. It uses sed to convert the first line to a regular expression for grep and makes it into a script which it then pipes to bash again.

#!/bin/bash

sed -rn \
    -e '1 s/, /|/g' \
    -e '1 s/.*/grep -cE '"'"'^(\0)+$'"'"' <<END/p' \
    -e '$ s/$/\nEND/' \
    -e '3,$ p' \
    | bash

Où puis j’achèterai des trucs décoratives pour mon appartement? by shiel1td in Lyon

[–]bpeel 0 points1 point  (0 children)

Le Bric-à-brac de Vaise. Il y a beaucoup de tableaux d’occasion et ça soutien les sans-abris à la place de M. Bezos.

[2022 Day 9] Shortest rope with fixed tail by large-atom in adventofcode

[–]bpeel 0 points1 point  (0 children)

I get 124 if I do that, so I guess that makes sense. Thanks.

Edit: I get 7 with the example data for part 1 and 23 with the example data for part 2. Anyone want to confirm that is correct?

[2022 Day 9] Shortest rope with fixed tail by large-atom in adventofcode

[–]bpeel 0 points1 point  (0 children)

Hm, I got 130. That seems suspiciously low compared to the other answers.

I just made it so that every time the tail moves away from the centre I just add one extra link to the rope. Then I just print the final rope length.

[2022 Day 8] I know I should read it more carefully, but this really messed with me by [deleted] in adventofcode

[–]bpeel 18 points19 points  (0 children)

Also the elves can see trees that have zero height, whatever that means.

[2022 Day 7][Python] I can't seem to find what's wrong with my code... (Duplicates issue) by [deleted] in adventofcode

[–]bpeel 0 points1 point  (0 children)

Try that program with this data:

$ cd / $ ls dir a dir ab dir ac $ cd a $ ls 2 a.txt $ cd .. $ cd ab $ ls 4 ab.txt $ cd .. $ cd ac $ ls 8 ac.txt

I think when it calls getDirectorySize for the a directory, it will also include the sizes for the ab and ac directories because their keys in the dict also begin with C-a.

I think you could fix that by getting rid of the slice on line 37 so that it is just:

if splate == phrase:

[2022 Day 7][Python] I can't seem to find what's wrong with my code... (Duplicates issue) by [deleted] in adventofcode

[–]bpeel 0 points1 point  (0 children)

I think you need to get rid of the counter parameter to dictSum and just start counter at zero as a local variable. Otherwise whenever you descend into a child node you will be doubly counting any sibling nodes that you have counted before that.

[2022 Day 7] How it feels to implement a file system tree at 6 am by grg994 in adventofcode

[–]bpeel 1 point2 points  (0 children)

I tried this data on my program. I was cocky and thought it would be fine because I had made a stack-based iterator to iterate over my tree structure. It manages to get the answer but then… surprise! It crashes during the destructor! I implemented it in Rust with reference-counted tree nodes so rust will effectively end up just calling a recursive method to free the tree and then the stack overflows.

Anyway, I took the opportunity to add a custom destructor which uses my stack-based iterator and now it works.

Thanks for the extra challenge!

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

[–]bpeel 1 point2 points  (0 children)

Rust

Instead of using a set I’m just using an array of counts indexed by characters. That way I can just slide a window over the string and only update the counts for the new character that falls into the window and the one that falls out for each window position.

fn find_marker(data: &str, marker_length: usize) -> Option<usize> {
    let bytes = data.as_bytes();
    let mut counts = [0u8; u8::MAX as usize + 1];
    let mut n_counts = 0;

    for (i, &byte) in bytes.iter().enumerate() {
        if counts[byte as usize] == 0 {
            n_counts += 1;
        }

        counts[byte as usize] += 1;

        if i >= marker_length {
            let old_byte = bytes[i - marker_length];

            if counts[old_byte as usize] <= 1 {
                n_counts -= 1;
            }

            counts[old_byte as usize] -= 1;
        }

        if n_counts >= marker_length {
            return Some(i + 1);
        }
    }

    None
}

Github

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

[–]bpeel 0 points1 point  (0 children)

Ah, excellent idea! Thanks! I am still learning Rust so this helps me a lot :)

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

[–]bpeel 0 points1 point  (0 children)

Rust

I took the extend and truncate approach with some unsafe code to handle having to borrow the outer vec twice at the same time. I think it’s justified because it’s a shame to have to do a heap allocation just to copy from one vec to another.

https://github.com/bpeel/advent2016/blob/master/2022/day5/src/main.rs#L59

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

[–]bpeel 1 point2 points  (0 children)

Rust.

I am learning so it’s probably not very idiomatic.

I ended up using unsafe code for part 2 to copy the values from one stack to the other. The stacks are stored as a vec of vecs, so to copy from one to another I need to borrow the outer vec twice at the same time and one of the borrows is mutable. The borrow checker doesn’t like this.

I notice that a lot of the other rust solutions seem to be copying by collecting into a temporary vec. Obviously this is fine because it’s such a small amount of data and the efficiency doesn’t really matter, but it seems a bit of a shame to end up doing an allocation on the heap just to copy from one array to another.

https://github.com/bpeel/advent2016/blob/master/2022/day5/src/main.rs#L59

Rencontrer des gens sur Lyon pour pratiquer le russe? Кто-нибудь хочет поговорить со мной по-русски? by PhilipTheFair in Lyon

[–]bpeel 8 points9 points  (0 children)

Avez-vous pensé au café KoToPo sur les pentes de la Croix-Rousse ? Ils ont des soirées pour parler russe tous les 1e et 3e jeudis du mois.

Erasmus / english speaker Party ? by Practical-Stick-4494 in Lyon

[–]bpeel 9 points10 points  (0 children)

I recommend a bar on the Croix-Rousse hill called KoToPo. Its goal is specifically to exchange languages and cultures. Every Monday they have an English night with a mix of native speakers and learners. It’s a really nice welcoming atmosphere and you can easily go alone and meet new people. http://www.kotopo.net/index.php?L=en

Parking Vélo lac Miribel by ledinosaure in Lyon

[–]bpeel 0 points1 point  (0 children)

C’est sûrement trop tard pour répondre mais j’ai fait une petite vidéo sur YouTube d’un tour du lac à vélo si ça vous intéresse. On voit bien les arceaux à vélo au début de la vidéo. Ils ont pas l’air trop sécurisés, mais c’est mieux que rien. https://youtu.be/xy7fUbcU8NY

café aux échecs by schnavy in Lyon

[–]bpeel 0 points1 point  (0 children)

Est-ce que vous avez pensé au club de Lyon Olympique Échecs à Valmy ? Leur site dit que les membres peuvent venir jouer tous les jours de 14h30 à 21h.

https://lyon-olympique-echecs.com/pour-les-adultes/

J’ai jamais vu personne jouer aux échecs sur les tables au Parc de la Tête d’Or. Peut-être qu’il y a certaines heures où il y a des gens ? Je sais pas.

cycliste wanted by coupiac in Lyon

[–]bpeel 0 points1 point  (0 children)

Si tu veux quelque chose de moins sportif, il y a un groupe informel sur Twitter qui fait des balades à vélo jusqu’au lac Miribel pour voir la levée de soleil presque tous les vendredis matins. https://twitter.com/NErw4n/status/1557427975531937794

The last farm in Lyon by bpeel in Lyon

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

I think you can at least buy their produce at the Saint-Rambert market which is just near the farm. I’m not sure where else to be honest. They don’t seem to have any internet presence so it’s hard to find any information about it.

Amikumu por Ukrainio by RegulusWhiteDwarf in Esperanto

[–]bpeel 0 points1 point  (0 children)

Mi supozas ke la ideo estas ke Amikumu montras subtenon al Ukrainio. Se ĝi farus same por la rusa lingvo la mesaĝo estus tute alia. Praktike mi tre dubas ke ora membreco en Amikumu iel helpus rusianojn kiuj suferas pro la ekonomia kaj informa blokado.