Skip to content

Katas

Level: reference · the practice track

One line: The lessons explain; the katas make you predict. Each one lives on the page for the topic it teaches — this is the only place they are put in an order.

Where a kata lives

A kata belongs to its topic, not to a folder of its own. The page that explains the byte is the page that asks you to write one down, under a ## Practice heading near the end, with the answer folded into a <details markdown="1"> block.

That is deliberate, and the reason is that folders are URLs. A topic — the byte, the code point, grep's locale — is stable for years; a sequence is not. The moment a kata belongs between K1 and K2, a K01_…/ folder either gets renumbered, breaking every link anyone saved, or starts lying about its own order. So the sequence lives here, in a table that costs nothing to reorder, and the numbers below are labels rather than addresses. Same rule as the sidebar: order is presentation, so it belongs in a page, never in a path.

Every answer here is printed by a program, recorded as an answer key and run by CI on Ubuntu and macOS with every other example in the library — so a solution cannot rot into one that no longer says what the page says. check_katas.py enforces that, and the rules are written down in CONTRIBUTING.md.

The katas

# Kata Lesson Level
K1 One byte, four readings — and the byte decides none of them A byte is eight bits 101
K2 Turn the odometer in your head — five hex questions, one carry Counting in hexadecimal 101
K3 Four bits at a time, both ways — then find the byte boundary in octal Hex is a shorthand 101
K4 Read the three columns off a file whose bytes you chose Reading a hex dump 101
K5 Thirteen bytes at three widths, and where the ragged piece falls Grouping is a choice 101 → 201
K6 The hash field that arrived one character short, read three ways Hex: a number, or a picture of bytes 201
K7 Two columns for four expressions — and where the loss happens in each language Arithmetic has its own width 101 → 201
K8 Four bytes: 01 00 00 00, and which two of the four answers are the file The bytes do not say which end 101 → 201
K9 Say which base the field is in — five questions, two brackets and one dump Which base did you mean? 201
K10 Three ASCII tricks, and the four characters that break them A character is a number 101
K11 Rotate, rotate back, then step outside ASCII and lose both guarantees Rotation is not encryption 101 → 201
K12 How many lines is this string? Three answers, all correct Control characters 101
K13 Five doors, and the one byte that is valid UTF-8 and welcome nowhere The NUL byte 201
K14 One byte, four tables — and the byte that settles the superset question Code pages 101 → 201
K15 Four code points read as addresses, and what each costs to write Unicode code points 101 → 201
K16 Four spellings of é, then the character \u cannot reach Writing a code point 201
K17 Five claims: which go in a bug report without a version stamp? The table has a version 201
K18 Six strings, three of them one user — and when folding is the bug Preparing a string 301
K19 Five numbers for one Polish word, and the letter that does not come apart A code point is not a character 201
K20 Five checks that all say no, and only one for the right reason Confusables and scripts 301
K21 Five ways to type one variable name, and the language that says so Unicode in identifiers 301
K22 Encode four characters with a pencil, then the one that is not a character UTF-8 by hand 101 → 201
K23 One bad byte, and how much of the check survives the call Validation is a boundary 201 → 301
K24 Two spellings of a slash, and the filter that only sees one Overlong sequences 301
K25 Build the surrogate pair by hand, then explain U+10FFFF UTF-16 and surrogates 201
K26 Write the bytes for six encodings, then name the CSV column Byte order and the BOM 201
K27 Five lines, two loud failures and two quiet wrong answers Encode and decode are verbs 101
K28 Name the culprit from the garbage, and say which garbage is repairable Mojibake 101 → 201
K29 One character through four channels, and what each one wraps Escaping into ASCII 201
K30 Predict four output lengths, then find the 4/3 that is not there Binary to text 201
K31 Four Base32 menu entries, and the one that is a different encoding The alphabet is not the encoding 201
K32 Seven numbers for one two-character string An encoding is four layers 201
K33 Six error policies, and the only one you can reverse Encode, decode and errors 101 → 201
K34 Nine ways out of one string, and the two bytes it will not carry Bytes that are not text 201
K35 Two spellings, four forms, and the lookup that raises nothing Normalization 201
K36 Five refusals, one invariant String is bytes that promise UTF-8 101 → 201
K37 Four numbers, one character — and the fifth, which is the first again char is four bytes 101 → 201
K38 Three contracts for four bytes, and the byte that changes the verdict From UTF-8, and lossy 201
K39 Where may you cut "żółw"? — five indices, and a field of five bytes Slicing by byte 201
K40 Three doors out of one filename, and the only one that hands it back OsStr, Path, and WTF-8 301
K41 A file with a letter in it and zero lines, and the loop that drops it The trailing newline 101 → 201
K42 Three decisions about one newline byte, and the row that needs all three A character and its bytes on one line 101
K43 Five readings of six bytes -- which column is the file? Inspecting a file 101 → 201
K44 Six variables, and whether any of them changes a Python len() Locale and LC_CTYPE 201
K45 One file, four answers, and which one the kernel consults File type is four questions 201
K46 Three scripts, six answers, and the two that surprise you The first two bytes 101 → 201
K47 Assemble the escape sequence, then find the byte nobody escapes Terminal hyperlinks, and the URI that is not one 201
K48 Three bytes that are the fix and the bug at once A BOM in a CSV 101 → 201
K49 Totals right to the cent, keys that match nothing CRLF vs LF 101 → 201
K50 Five scars, and the constraint that made each one right From the telegraph to Unicode 201
K51 Six properties in six lines, and the bill it pays Why UTF-8 won 201
K52 What those four systems actually adopted, and why they cannot leave Why UTF-16 stayed 201
K53 Five rules, and the line of code each one forbids UTF-8 everywhere 201
K54 Five signatures, and the one the compiler refuses Rust strings in practice 201 → 301
K55 Four habits, and the bytes method that is right and still a bug Python text in practice 201
K56 Six round trips, and the three that come back unchanged "Handles Unicode" is four questions 301
K57 What does a dot match? Four answers, and who decided grep on text that is not ASCII 201
K58 Three marks, one missing encoding, and three defaults that hide a file ripgrep — the Rust grep 201
K59 The only engine that can match one grapheme, and what it stops telling you PCRE2 — the other regex engine 201
K60 Two stages, and why removing a container fixes no encoding --pre and -z — decompress, then decode 201
K61 A file cat can open and find -name cannot see find, and filenames that are bytes 201
K62 Four filenames, and how many survive the naive pipeline xargs splits on the wrong things 201
K63 The edit that works, the locale that breaks it, and the -i with no portable spelling sed matches patterns, not bytes 201
K64 Whose awk is this, and what does length() count? awk is three programs 201
K65 How long is this variable, and which two bytes never arrive? The shell has no string type 201
K66 -b or -c, and the machine that changes the answer cut counts what it is told to count 201
K67 Delete one letter, damage two words -- sets against sequences tr and sort work a byte at a time 201
K68 Four ways to ask if two files match, none of them the question you meant diff compares lines, cmp compares bytes, neither compares text 201
K69 Three tools that take text as bytes, and the one with no opinion split cuts characters, paste cuts delimiters, look needs a sorted file, tee does nothing 201
K70 Seven ways to blank a file, and the one that leaves the old bytes behind touch, : > and install are not three spellings of one command 201
K71 Why the pairs came out swapped, and what a grouping width claims hexdump is a format engine wearing six presets 201
K72 Edit the dump and put it back -- and find the column that was ignored xxd is the dump you can put back 201
K73 Read the interface as a C type, and say why -a cannot be quoted od reads types, not bytes 201
K74 Six columns, and the one no dump tool has uni — the character's name 101 → 201
K75 Predict the row, then name the tables, then read a bare number uni -h, line by line 201
K76 Four ways to type it, and the two that identify the character Typing a character you cannot type 101 → 201
K77 One byte string, two readers, and a duplicate JSON key Two readers, one byte string 301
K78 Five paths, two orders, and why checking harder is not the fix The check that ran too early 301
K79 Six signups, three classes, and who owns each one Two people, one account 301
K80 Five bytes that end a field for somebody else The byte that means something to somebody else 301
K81 Two readers of one file, and the one with no access to the bytes What you see is not what runs 301
K82 Forty pages nobody opens, and how to find them without the names The encoding man pages nobody opens 201
K83 Out of date, or wrong? -- and the three dates a page carries A page has a date 201
K84 The flag no page mentions, and the two platforms that disagree about it What the page does not say 201
K85 Five damaged fields, and the question that sorts them The mojibake round trip 201
K86 Three ways to make one string wider, and the four calls that move a number A str in memory 201
K87 One file, four readings, and the same script on three machines Opening a file 201
K88 Six bytes, and a format spec you have not been given Bytes, hex and int 201
K89 Four iconv commands over one six-byte file iconv 201
K90 Four writes that look identical, and the one character that breaks the tie printf writes bytes 101
K91 Three files, one verdict, and only one of them is ASCII file guesses 101
K92 The same script, two commands, and the line that never arrives A pipe is not a terminal 201
K93 Five code points, and the one a UTF-8 encoder actually refuses Noncharacters and the private use areas 201
K94 Five byte strings, one tag, and the one an encoder will never write UTF-7, and the seven-bit transport 201 → 301
K95 Four records, one lie — and the number the checksum hands back A record has to say what it is, how long it is, and whether it arrived 201 → 301
K96 Six questions about fourteen bytes, and the one with no answer Packing a record 201 → 301
K97 Six expressions, and the requirement each one is about "Supports Unicode" is a level, not a yes 301
K98 Four pairs, and the one no level can separate Sorting and collation 301
K99 Five pairs, and the checks that reach them The hard strings 301
K100 Four files, twelve answers, and a rename Binary is a verdict, not a property 101
K101 Five fields cut to fit, and the one a Go front end refuses rune is an int32 201