tree-rotation

Some simple tools to test hypotheses about amortized tree operations.

Initiated by the puzzle at: https://github.com/koengit/puzzle2026

This repository contains two main components:

  1. A browser playground for interactively stepping through move sequences and visualizing the resulting tree.
  2. A Haskell program, tree-rotation, for exact and approximate high-score (rotations/constructors) search and plotting.

The project is licensed under the BSD 3-clause license; see LICENSE.

Web playground

The interactive page lives at play/index.html.

It is a self-contained visualization of the tree-rotation game. The page shows:

How to play

Open play/index.html in a browser, then type a move string such as ccrtt into the input field.

The displayed tree and score is determined by the moves up to the current cursor position. Thus, you can step backward and forward through a longer sequence and inspect intermediate states without deleting text. If the move sequence is illegal, the tree pane shows a large red X.

Command-line solver

The executable tree-rotation solves the game by exhaustive exploration of the game tree.

By default it solves the game for the number N of concatenation moves, starting at N = 1, and keeps running for N, N+1, N+2, ... until interrupted. For each solved N, it prints the winner, i.e., the move sequence with the most rotations, and appends a CSV row with

n,score,ratio,iterations,moves

where score is the number of rotations, ratio is score / n, iterations is the search-specific work counter, and moves is the winning move trail.

Search modes

Command-line options

tree-rotation [--verbose] [-o|--output FILE] [--start N] [--init MOVES] [--plot] [--full]
              [--dfs | --random | --random NNN | --mcts | --mcts NNN]

Build and run

This project is a Cabal package named tree-rotation and builds with the executable of the same name.

cabal build
cabal run tree-rotation -- --help

To locate the built executable directly:

cabal list-bin tree-rotation