advent-ocr

Crates.ioadvent-ocr
lib.rsadvent-ocr
version0.1.3
sourcesrc
created_at2024-10-29 01:24:54.446665
updated_at2024-10-29 21:40:21.79373
descriptionConverts ASCII-art representations of letters generated by Advent of Code puzzles into a String containing those letters.
homepage
repositoryhttps://github.com/nbanman/advent-ocr
max_upload_size
id1426264
size19,851
(nbanman)

documentation

README

advent-ocr

A Rust function to convert ASCII-art representations of letters generated by Advent of Code puzzles into a String containing those letters. Through 2023, these puzzles are:

  • 2016, Day 8
  • 2018, Day 10
  • 2019, Days 8 and 11
  • 2011, Day 13
  • 2022, Day 10

Installation

Add this to your Cargo.toml file:

[dependencies]
advent-ocr = "0.1.3"

Usage

There is one function, ocr(), that takes one argument, image.

image can take the following types:

  • &str
  • (&Vec<bool>, usize), a tuple consisting of a Vec of bools and the width of a line.
  • (&Vec<bool>, usize), a tuple consisting of a Vec of chars and the width of a line.
  • &Vec<Vec<bool>>, a Vec of a Vec of bools.
  • &Vec<Vec<char>>, a Vec of a Vec of chars.

For &str and the char-based Vecs, '#' is considered part of a letter and all other chars are considered blank space. For the bool-based Vecs, true is considered part of a letter and false is considered blank space.

use advent_ocr::ocr

let image = r"
.##..###...##.
#..#.#..#.#..#
#..#.###..#...
####.#..#.#...
#..#.#..#.#..#
#..#.###...##.
    ";

let s = ocr(image);
println!("{s}"); // prints "ABC"

Warning/Credits

This library recognizes the two font sizes used in Advent of Code puzzles, but neither font alphabet is complete. This draws on the efforts of mstksg and possibly others. If the function does not recognize a letter, send me a message with the image that failed to render, and I will add it!

License

Licensed under either of

at your option.

Commit count: 11

cargo fmt