499 points | 7 solves
Description:
Full mind of mind, Empty belly of belly
You have recieved a gift.
beezchurger
Challenge author: gammascreed
Files: beezchurger.gif
TL;DR: Each frame's palette is a permutation of frame 0's palette. Specifically, each frame's palette is rotated rightward with respect to frame 0's. The number of rightward rotations is an ASCII character code.
The following is written in a "literate Rust" fashion.
Housekeeping:
use std::{collections::BTreeMap, fs::File};
fn main() {
Initialize the GIF decoder:
let opts = gif::DecodeOptions::new();
let f = File::open("beezchurger.gif").unwrap();
let mut decoder = opts.read_info(f).unwrap();
Declare the RGB to index map, which maps RGB colors to their index in frame 0's palette:
let mut rgb_to_index = None::<BTreeMap<[u8; 3], usize>>;
Start decoding frames:
while let Some(frame) = decoder.read_next_frame().unwrap() {
Get the frame's palette, chunked by threes:
let (pal, []) = frame.palette.as_ref().unwrap().as_chunks::<3>()
else { unreachable!() };
Initialize the RGB to index map if it hasn't been initialized yet:
let rgb_to_index = rgb_to_index.get_or_insert_with(||
pal.iter().copied().enumerate().map(|(i, x)| (x, i)).collect());
Get the corresponding character and print it:
let c = (256 - rgb_to_index[&pal[0]]) as u8 as char;
print!("{c}");
}
Print a newline for courtesy and leave:
println!();
}
© 2025 Robert B. Langer, CC BY 4.0