Wordle, Grep
Wordle and grep rebuilt in Haskell, a pure functional language — a guessing game and a stream matcher, both as pure functions over lazy lists.
╌╌╌╌
Two staples rebuilt in Haskell, a purefunctional language: Wordle, the five-letter guessing game, and grep, the stream matcher.
Wordle picks a random five-letter word from a corpus and scores each guess per letter — right letter in the right place, right letter in the wrong place, or absent. The duplicate-letter case needs a two-pass scan: mark the exact matches first, then match the remaining guess letters against the pool of still-unmatched target letters, so a repeated letter is never credited twice. The round is won when the word is guessed, usually within five tries; an infinite mode keeps dealing new words. The original game was made by Josh Wardle.
Grep matches a pattern against a text stream line by line and prints the lines that hit — search over local file contents. In Haskell the matcher is a pure function over a lazy list of lines, so a file is consumed as a stream and only as far as needed, rather than read into memory whole.
References
- Project repository
- Reference notes: String Matching: Naive & Rabin–Karp
- Reference notes: String Matching: KMP & the Z-Function
╌╌ END ╌╌