this post was submitted on 02 Jan 2025
4 points (100.0% liked)

Advent Of Code

997 readers
1 users here now

An unofficial home for the advent of code community on programming.dev!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

AoC 2024

Solution Threads

M T W T F S S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 2 years ago
MODERATORS
4
Visualisation Megathread (programming.dev)
submitted 1 month ago* (last edited 1 month ago) by [email protected] to c/[email protected]
 

Visualizations are hard, and take time, so here is a thread to highlight the visualizations that we have found/created.

Please feel free to post your visualisations!

top 5 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 1 month ago

https://youtu.be/fVE2lfZNCCI

Day 15 - Warehouse Woes

Pt2 only, part 1 isnt terribly interesting.

[–] [email protected] 1 points 1 month ago
[–] [email protected] 0 points 1 month ago (2 children)

https://www.youtube.com/watch?v=OR9QTQ2pg3s

Day 14 - Robots.

Try find the image :D

If no one finds it in the next few days, I'll update with a timestamp.

[–] [email protected] 1 points 1 month ago

For anyone else doing rust, this might be useful:

It basically generates an asciicinema/asciicast file, which is then can be used to render a video.

use std::fs::File;
use std::io::Write;
use std::process::Command;

pub struct Recorder {
    filename: String,
    output: File,
    width: usize,
    height: usize,
    position: f32,
    frametime: f32,
    do_render: bool,
}

// Generate: https://docs.asciinema.org/manual/asciicast/v2/
impl Recorder {
    pub fn new(filename: &str, w: usize, h: usize, framerate: u32, do_render: bool) -> Recorder {
        let mut r = Recorder {
            filename: String::from(filename),
            output: File::create(format!("{filename}.cast")).unwrap(),
            width: w,
            height: h,
            position: 0f32,
            frametime: 1f32 / framerate as f32,
            do_render,
        };
        r.init();
        r
    }

    fn init(&mut self) {
        self.output
            .write_all(
                format!(
                    "{{\"version\": 2, \"width\": {}, \"height\": {}}}\n",
                    self.width, self.height
                )
                .as_bytes(),
            )
            .unwrap();
    }

    pub fn println(&mut self, s: &str) {
        let line = format!("{s}\n");

        self.print(&line);
    }

    pub fn print(&mut self, s: &str) {
        let escaped = serde_json::to_string(&(self.position, "o", s)).unwrap();

        self.output
            .write_all(format!("{escaped}\n").as_bytes())
            .unwrap();
    }

    const RESET: &'static str = "\u{001b}[H\u{001b}[2J\u{001b}[3J";

    pub fn sleep(&mut self, d: f32) {
        self.frametime += d;
    }

    pub fn new_frame(&mut self) {
        self.position += self.frametime;

        self.print(Self::RESET);
    }
}

impl Drop for Recorder {
    fn drop(&mut self) {
        if self.do_render {
            let castname = format!("{}.cast", self.filename);
            let gifname = format!("{}.gif", self.filename);
            let mp4name = format!("{}.mp4", self.filename);

            self.output.flush().unwrap();
            let mut command = Command::new("agg");
            command.arg(castname);
            command.arg(gifname.as_str());
            let mut proc = command.spawn().unwrap();
            proc.wait().unwrap();

            let _ = std::fs::remove_file(mp4name.as_str());
            let mut command = Command::new("ffmpeg");
            command.arg("-i");
            command.arg(gifname.as_str());
            command.arg(mp4name.as_str());
            let mut proc = command.spawn().unwrap();
            proc.wait().unwrap();
        }
    }
}
[–] [email protected] 1 points 1 month ago

I downloaded the video and watched it at x16 speed. I actually spent longer trying to find a working federating instance to post my reply than I spent searching for the tree.https://www.youtube.com/watch?v=OR9QTQ2pg3s&t=1482s