Learn Larzscript
57 real, tested Larzscript programs - algorithms, data formats, CLI tools, web, data structures, and money-native tasks no other language treats as a language primitive. Every example is real code with real captured output, not pseudocode.
- Algorithms (11)
- Data formats (6)
- CLI & text (6)
- Web (10)
- Data structures (4)
- Money-native (8)
- Date & time (1)
- App patterns (11)
Algorithms
11 real, tested examples.
The classic interview warm-up: print 1 to N, but Fizz for multiples of 3, Buzz for multiples of 5, FizzBuzz for both.
algorithmsReverse a String in LarzscriptFlip a string end to end - one of the smallest real string algorithms, and a good first look at the str package.
algorithmsCheck if a String is a Palindrome in LarzscriptDetect whether a string reads the same forwards and backwards, ignoring case, spaces and punctuation.
algorithmsSort a List in LarzscriptSort a list of numbers - and see exactly how many comparisons and swaps each algorithm actually costs.
algorithmsBinary Search in LarzscriptFind a value in a sorted list in O(log n) instead of scanning every element.
algorithmsFind the Greatest Common Divisor (GCD) in LarzscriptCompute the greatest common divisor of two numbers with the Euclidean algorithm - and see every step.
algorithmsCheck if a Number is Prime in LarzscriptTest primality, and generate a sieve of primes up to a limit.
algorithmsGenerate Fibonacci Numbers in LarzscriptCompute the Nth Fibonacci number - iteratively, so it stays fast even for large N.
algorithmsMatch a Regular Expression in LarzscriptTest, extract, and replace with a real (if deliberately small) regex engine - literals, classes, quantifiers, anchors.
algorithmsCompute the Edit Distance Between Two Strings in LarzscriptThe Levenshtein distance: the minimum number of single-character insertions, deletions and substitutions to turn one string into another.
algorithmsFind the Shortest Path with A* Search in LarzscriptSearch a 2D grid for the shortest route around obstacles - the real A* algorithm (an open set ordered by f = g + h), not a maze-solver toy.
Data formats
6 real, tested examples.
Parse a JSON string into real Larzscript dicts and lists, and turn data back into JSON text.
data formatsRead and Parse a CSV File in LarzscriptParse CSV text into rows, or straight into dicts keyed by header - including quoted fields with embedded commas.
data formatsEncode and Decode Base64 in LarzscriptBase64-encode arbitrary text (or decode it back), the standard way binary-ish data travels safely through text-only channels like JSON or URLs.
data formatsParse a URL in LarzscriptBreak a URL into its scheme, host, path and query parameters, and safely join a base URL with a relative path.
data formatsParse YAML in LarzscriptParse a YAML document (nested mappings, lists of scalars) into real Larzscript data.
data formatsParse an INI Config File in LarzscriptRead a classic `[section]` / `key = value` config file into a nested dict.
CLI & text
6 real, tested examples.
Build a real command-line tool with named subcommands and auto-generated help, the shape every larzscript-* showcase app in this ecosystem uses.
cli & textParse Command-Line Arguments in LarzscriptParse --flag=value pairs and positional arguments out of argv, without a full CLI framework.
cli & textRead a File Line by Line in LarzscriptRead a text file's contents and split it into lines - the everyday first step of any script that processes a file.
cli & textPretty-Print a Table in LarzscriptRender tabular data as an aligned ASCII table for the terminal, or Markdown for a README.
cli & textColorize Terminal Output in LarzscriptAdd ANSI colors to terminal output, with automatic NO_COLOR support so piped output stays clean.
cli & textGenerate a URL-Safe Slug from Text in LarzscriptTurn an arbitrary title into a clean, URL-safe slug - accented characters transliterated, not just stripped.
Web
10 real, tested examples.
Fetch a URL and read its status code and body - or parse a JSON API response directly.
webSign and Verify a Webhook Payload in LarzscriptSign an outgoing webhook payload with HMAC-SHA256, and verify an incoming one - the same shape real payment/webhook providers use.
webHash Data with SHA-256 in LarzscriptCompute a real SHA-256 hash and an HMAC-SHA256 message authentication code.
webGenerate a UUID in LarzscriptGenerate random (v4) and time-sortable (v7, ULID, nanoid) unique identifiers.
webGenerate a One-Time Password (TOTP) in LarzscriptGenerate and verify RFC 6238 time-based one-time codes - the same 6-digit codes an authenticator app shows.
webRender a Template in LarzscriptFill a string template with dotted variables and a loop - no framework needed for a page, an email body, or a report.
webBuild a Minimal HTTP Server in LarzscriptAnswer a real TCP connection with a real HTTP response - the raw socket_listen/accept/read/write builtins under the tcp package's serve() helper.
webValidate an Email Address in LarzscriptCheck whether a string is a plausible email address - no regex of your own to get subtly wrong.
webValidate a Web Form Submission in LarzscriptValidate a whole submitted record against a schema at once - required fields, ranges, and an allowed-choices list - with automatic type coercion.
webGenerate a QR Code in LarzscriptEncode text into a real, spec-accurate QR code - Reed-Solomon error correction and all - rendered as ASCII art.
Data structures
4 real, tested examples.
The two most basic linear data structures - last-in-first-out and first-in-first-out - named explicitly instead of just using a bare list.
data structuresImplement a Binary Search Tree in LarzscriptInsert values into a binary search tree and read them back in sorted order.
data structuresImplement a Priority Queue (Binary Heap) in LarzscriptAlways get the smallest (or, with a key function, largest/custom-ordered) item next - the classic array-backed binary heap.
data structuresImplement a Trie for Autocomplete in LarzscriptThe structure behind every autocomplete box: insert words, then ask what starts with a given prefix in O(prefix length), not a full scan.
Money-native
8 real, tested examples.
Divide a bill among people so it reconciles exactly to the cent - no language other than Larzscript treats this as a stack primitive rather than app-level logic.
money-nativeHold Funds in Escrow in LarzscriptHold a payer's funds, then release them to a payee or refund them back - using the language's own wallet and pay keywords, not a bolted-on library.
money-nativeRate-Limit API Requests in LarzscriptToken-bucket rate limiting in about 20 lines - cap a caller to N requests with a steady refill rate instead of a blunt fixed window.
money-nativeBuild a Subscription Paywall in LarzscriptGate a feature behind a recurring charge - using paywall, subscribe, and require as real language keywords, not a bolted-on billing library.
money-nativeCalculate a Loan Amortization Schedule in LarzscriptSimple interest, compound interest, and a full monthly amortization schedule - with exact Money math, not float-drifted cents.
money-nativeConvert Currency in LarzscriptConvert an amount between currencies with a settable rate table - fully offline, no API call, no hidden currency-tagging assumptions.
money-nativeKeep a Double-Entry Ledger in LarzscriptPost debits and credits that always balance - the accounting equation holds after every single posting, not just at the end.
money-nativeProrate a Mid-Cycle Subscription Upgrade in LarzscriptA customer upgrades plans partway through a billing period - credit the unused days on the old plan, charge only the difference for the new one.
Date & time
1 real, tested examples.
App patterns
11 real, tested examples.
Retry a flaky call a few times, waiting longer between each attempt, instead of failing on the first hiccup or hammering a struggling service.
app patternsMemoize a Function in LarzscriptCache a function's results so calling it twice with the same input only does the real work once.
app patternsImplement a State Machine in LarzscriptDeclare states and transitions, fire events, and let the machine reject anything that isn't a legal move - a document workflow (draft -> review -> published) in a few lines.
app patternsPaginate a List in LarzscriptSlice a list into pages with the has_next/has_prev/1-based-index bookkeeping every list-showing page needs, without hand-rolling the off-by-one math again.
app patternsCompare Semantic Versions in LarzscriptParse major.minor.patch versions, compare them correctly (1.2.0 < 1.10.0, not a naive string compare), and check a version against a real range constraint.
app patternsCache Values with an LRU Cache in LarzscriptCache expensive results with a bounded, least-recently-used eviction policy, plus one-line memoization for a whole function.
app patternsDebounce and Throttle a Function in LarzscriptTwo different ways to rate-limit how often a function actually runs: debounce waits for a quiet gap, throttle guarantees a minimum spacing.
app patternsBuild a Persistent Key-Value Store in LarzscriptInsert, update and query records that survive the process exiting - a tiny document store backed by a plain JSON file.
app patternsRotate and Archive Log Files in LarzscriptOnce a log file crosses a size threshold, shift it into numbered backups and start a fresh one - the same scheme logrotate uses.
app patternsBuild a Pub/Sub Event Bus in LarzscriptDecouple producers from consumers with dot-segmented topics and wildcard subscriptions.
app patternsImplement a Circuit Breaker in LarzscriptStop hammering a failing dependency: after enough real failures, fail fast for a cooldown period instead of trying again.