Skip to content
/ codex Public

Programming problems, solved with Literate Programming and verified with tests

License

Notifications You must be signed in to change notification settings

listx/codex

Repository files navigation

Codex

Introduction

This project aims to capture my notes for studying various programming problems (data structures and algorithms). Have a look at the problems in Section <a href=”* Problems”>* Problems.

For those curious about how these notes were created, check out Section <a href=”* Literate Programming Build System”>* Literate Programming Build System.

As for why this project is named Codex, I just think it’s a cool word that has the word “code” in it as a substring.

How to read this document

Please do not use the GitHub-rendered view of this file, as many things like links and citations simply do not work. Instead go to https://funloop.org/codex for the best experience, on a desktop or laptop screen (mobile devices don’t work very well, not to mention the missing Table of Contents sidebar).

Problems

Every problem gets its own README.org file in its own subfolder. The solutions are all in Python. All solutions are “standalone” in that none of them use any libraries other than what’s provided by Python’s standard libraries.

The problems are drawn mainly from [cite:@epip]. Other reference materials are cited where applicable. Below is a table of every problem, with tags that give a brief description of each one, and references.

NameTagsReferences
Paritybitwise[cite:@epip 27; @hd 96]
Rectangle overlapgeometry[cite:@epip 39]
Rearrange listarray, partitioning[cite:@epip 41]
Dutch national flagarray, partitioning[cite:@epip 43; @levitin 200; @sedgewick 296-301; @pearls 123; @cormen 186; @skiena 125-126]
Buy and sell stock oncearray[cite:@epip 51; @cormen 69]
Buy and sell stock twicearray[cite:@epip 53]
Interconvert strings and integersarray, string[cite:@epip 75]
Merge sorted linked listslinked list[cite:@epip 92]
Height-balanced binary treesbinary tree[cite:@epip 124]
Merge monotonically increasing streamspriority queue[cite:@epip 144]
Find first occurrence from sorted arraybinary search[cite:@epip 155]
Anonymous message from magazinehash table[cite:@epip 175]
Intersection of two sorted arrayssorting[cite:@epip 194]
Validate binary tree as BSTbinary tree[cite:@epip 213]
Tower of Hanoirecursion, binary tree[cite:@epip 233]
Maximum Subarraydivide and conquer, dynamic programming[cite:@epip 250; @pearls 77]
Making Changedynamic programming[cite:@epip 253; @taocp1 sec. 1.2.9]]

Data structures

Some problems can only be solved in an elegant way if we use particular data structures. See below for introductory discussions about some of these.

NameTagsReferences
Linked listlinked list[cite:@epip 91]
Stack (with “max” method)stack[cite:@epip 106]
Binary treetree[cite:@epip 123]
Binary search treetree[cite:@sedgewick 396]
Heaptree, heap, priority queue[cite:@sedgewick 308]

Appendix

Python tricks
There are some Python-language-specific tricks available for programming problems. You might want to skim over this if your Python skills are rusty.
Mathematics
Some (some would argue all) topics in programming have mathematical underpinnings.

Tests

DependencyWhy
Rufffor linting
Mypyfor enforcing type hints
Hypothesisfor property-based tests

All solutions to the problems are implemented in Python, and tested with basic unit tests and the Hyothesis property-based testing framework. Each problem’s discussion comes with its own test suite. All source code samples are linted as well with ruff and mypy. Testing has been extremely valuable in checking the correctness of the puzzle solutions collected in this work.

Literate Programming Build System

References

About

Programming problems, solved with Literate Programming and verified with tests

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published