Skip to content

About

GWEB Examples

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

268 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GWEB Examples

GWEB is a literate programming system for Go, modeled on Knuth and Levy's CWEB. This repository collects programs written in GWEB, most of them ports of Knuth's CWEB programs. All the documents are in Korean and are best read as typeset PDFs.

Each example directory includes the typeset PDF and the Go source, so you can read and run everything without building: try go run ./floyd or go test ./ziptree.

Building

To rebuild after editing a .gw file, you need gtangle, gweave, and luatex (with luamplib). Run make from the repository root.

make ziptree      # ziptree/ziptree.go + ziptree/ziptree_test.go + ziptree/ziptree.pdf
make matula-big   # change-file variant: matula/matula-big/matula.go + matula/matula-big/matula.pdf
make all          # every example (except the change-file variants)
make clean        # remove intermediate files and change-file variants

Examples

Puzzles and games

  • 15puzzle-korf1 — Finds minimum-move solutions of the 15 puzzle with Korf's iterative deepening.
  • sliding — A general-purpose engine for sliding block puzzles.
  • sliding-ui — Gives the sliding engine a browser front end: draw puzzles, watch animated solutions, and play by hand.
  • othello — Plays an interactive generalized Othello for p players on an m×n board.
  • topswops — Finds the longest-lasting decks in Conway's Topswops.
  • back-20q — Solves Don Woods's self-referential puzzle Twenty Questions.
  • back-pi-day — Solves Johan de Ruiter's 2018 Pi Day puzzle.
  • back-skeleton — Constructs Junya Take's skeleton multiplication puzzles.
  • perfect-partition-square — Michael Keller's puzzle of packing the 14 partitions of 7 into a 7×7 square.

Chessboards

  • nqueens-somers — Explains Jeff Somers's technique for counting solutions of the N queens problem.
  • nqueens-takaken — Squeezes more out of N queens with Takaken's eight symmetries and goroutines.
  • queenon-partition — Draws the partition of cells that Simkin used for the asymptotics of the number of n-queens solutions.
  • infty-queens — Computes the sequence obtained by greedily placing queens on an infinite chessboard (OEIS A065188).
  • back-warnsdorf — Explores knight's tours that follow Warnsdorf's rule, including every branch at ties.
  • perec — Reconstructs Georges Perec's Life: A User's Manual from its two constraints.

Gray-code listings

  • koda-ruskey — Generates all ideals of a forest poset in Gray-code order.
  • li-ruskey — Lists the 0/1 labelings that respect the constraints of a digraph along a Gray path.
  • spiders — Solves the problem of koda-ruskey and li-ruskey from the other side, closing the trilogy.
  • grayspan — Lists all spanning trees of a graph so that neighbors differ by a single edge.
  • spspan — Lists all spanning trees of a series-parallel graph so that neighbors differ by a single edge.
  • grayspspan — Combines grayspan and spspan to list spanning trees in Gray order in O(m+n+t) time.
  • spgraph — Turns spspan's series-parallel expressions into SGB graph files so they can be compared with grayspan.

Graphs and trees

  • tarjan-strong — Tarjan's strong components (Algorithm 7.4.1.2T).
  • tarjan-strong-and-weak — Strong components and Knuth's weak components (Algorithm 7.4.1.2W).
  • hopcroft-karp — Finds a maximum matching in a bipartite graph with the Hopcroft–Karp algorithm.
  • matula — Decides with Matula's algorithm whether a free tree is isomorphic to a subtree of another free tree.
  • canonize-bidigraph — Computes the canonical form of a bidirected graph.
  • back-graceful — Finds all graceful labelings of a graph.

Words and codes

  • commafree-eastman — Eastman's 1965 algorithm for constructing comma-free codes.
  • back-commafree4 — Finds the largest comma-free code of length 4 by backtracking.
  • co-debruijn — Builds de Bruijn cycles from interwoven coroutines, setting Knuth's simulated coroutines side by side with an iter.Pull version.
  • enigmatic-puzzle — Cracks the 125-letter enigmatic ciphertext of TAOCP 7.2.2.8.
  • wordcube — Builds symmetric 5×5×5 word cubes from five-letter words.

Shapes and patterns

  • polynum — Jensen's transfer-matrix method for counting fixed polyominoes.
  • back-dissect — Finds all ways to cut a square into pieces that fill another shape.
  • hyperbolic — Computes the tiling of the hyperbolic plane by 36°-45°-90° triangles.
  • dragon-calc — An interactive calculator for Dekking's generalized dragon curves and tile computations.
  • celtic-paths — Prints Celtic knots with Knuth's CELTICA/CELTICB fonts.

Numbers and counting

  • prime-sieve — Finds record prime gaps with a segmented sieve of Eratosthenes.
  • ulam-gibbs — Computes billions of Ulam numbers with Philip Gibbs's method.
  • back-pdi — Finds all perfect digital invariants of order m.
  • prjeuler152 — Solves Project Euler problem 152 with exact rational arithmetic.
  • floyd — Floyd's problem of splitting √1…√50 into two nearly equal parts.
  • pipe-organ — Counts the sounds that the pipe organ in Knuth's home can make, and checks the answer to TAOCP exercise 7.2.2-79.

Algorithms and data structures

  • ziptree — Tarjan, Levy, and Timmel's zip trees.
  • pairsums — Finds, with a Li Chao tree, the largest sum of pairwise products over all subarrays.
  • ntt — A guide to the fast Fourier transform and number-theoretic transforms.
  • perm — Floyd's random sampling algorithm.
  • squint — Handles lazy power series with a network of channels.

About

GWEB Examples

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages