← Latest papers
🤖 AI

CayleyR: Solving the TopSpin puzzle via cycle intersection

This paper introduces cayleyR, an R package that solves the TopSpin(n,k) permutation puzzle by employing an iterative bidirectional search with cycle intersection detection in Cayley graphs, enhanced by C++ hashing and optional Vulkan GPU acceleration.

Original authors: Yuri Baramykov

Published 2026-07-16
📖 6 min read🧠 Deep dive

Original authors: Yuri Baramykov

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

The Puzzle of the Infinite Maze

Imagine you are standing in a massive, invisible maze where every turn you take changes the entire layout of the world around you. This isn't just a game of "left or right"; it's a game of permutations, a branch of mathematics called group theory that studies how things can be rearranged. Think of a deck of cards: if you shuffle them, you create a new order. If you shuffle them again, you create another. The "Cayley graph" is a map of every single possible order those cards could be in, connected by the moves you make to get from one order to another.

The specific puzzle this paper tackles is called TopSpin. Imagine a circular track with numbered tokens (like beads on a necklace) and a window that can flip a few of them over. You can spin the whole track or flip the tokens in the window. The goal is simple: get the beads from a messy jumble back to their perfect, numbered order. The problem is that as you add more beads, the number of possible arrangements explodes. For just 20 beads, there are more ways to arrange them than there are atoms in the universe. Traditional computer methods, which try to check every single path one by one, get stuck in this infinite maze almost immediately. This paper introduces a new way to navigate that maze, not by walking every path, but by throwing darts and hoping two of them land on the same spot.


The Paper: Throwing Darts in the Dark

In this paper, Yuri Baramykov introduces a new software tool called cayleyR and a clever strategy to solve the TopSpin puzzle, even when the puzzle is huge. Instead of trying to map the entire maze from start to finish, the author uses a method called Iterative Cycle Intersection (ICI).

Here is how it works, using a playful analogy: Imagine you and a friend are lost in a giant, circular forest (the Cayley graph). You start at opposite ends, and you both want to meet in the middle.

  • The Old Way: You both try to walk every single path, step by step, marking every tree you see. This takes forever because the forest is too big.
  • The cayleyR Way: Instead of walking carefully, you both grab a handful of "magic seeds" (random sequences of moves). You plant them and watch them grow into giant, looping vines (cycles). Because the forest is circular, these vines eventually loop back on themselves.
  • The Intersection: You keep throwing these seeds and growing vines. Eventually, one of your vines will cross paths with one of your friend's vines. When they touch, you've found a meeting point! You can then trace the path from your start, along your vine, to the meeting point, and then follow your friend's vine backward to their start.

The paper explains that this "vine-growing" strategy is much faster than walking every path. The software generates random sequences of moves, calculates the loops they create, and checks if any of those loops overlap with the loops generated from the other side. If they don't overlap right away, the software picks the two vines that are closest to each other (using a "distance guide") and starts growing new vines from those points. It repeats this process until the two sides meet.

What the Paper Actually Found

The author didn't just invent the idea; they built a working computer program to test it. Here is what the experiments showed:

  • It works on big puzzles: The software successfully solved TopSpin puzzles with up to 20 tokens (where the number of possible arrangements is 20 factorial, or about 2.4 quintillion). This is a size that would crash traditional computers.
  • It's fast: In tests with 14 tokens, the computer found a solution in an average of 1.12 seconds. Even the hardest puzzles in the test were solved in under 3.5 seconds.
  • Not all seeds are equal: The paper tested different ways to choose which "magic seeds" (random move sequences) to plant. They found that choosing sequences that visit the most unique spots (called "most unique") was the most likely to find a solution (solving 83% of the test cases), but the paths it found were sometimes very long. Choosing sequences that visited the same spots over and over ("most repeated") was the most reliable for finding short paths quickly.
  • It's not perfect: The paper is very clear that the paths found are not necessarily the shortest possible path. The algorithm finds a path, not always the best path. However, the software includes a "post-processing" step that tries to shorten the path afterward, sometimes cutting the number of moves in half.

What the Paper Rules Out (and What It Doesn't)

It is important to know what this paper says it doesn't do:

  • It is not a guarantee of the shortest path: The author explicitly states that the Iterative Cycle Intersection algorithm does not guarantee the shortest route. It finds a solution, but it might take a detour.
  • It is not a magic bullet for every puzzle yet: The current version of the software is specifically designed for the TopSpin puzzle. While the author suggests the idea could work for other puzzles (like pancake sorting), the paper only proves it works for TopSpin.
  • The "Holographic" idea is just a guess: The paper mentions a fancy new theory called "holographic duality" that might help visualize these puzzles as shapes on a sphere. However, the author admits this is speculative. They say it "remains to be explored" and that the current version of the software only uses this for pretty pictures, not for actually solving the puzzle.

The Bottom Line

This paper presents a new, playful, and highly effective way to solve a very hard math puzzle. By stopping the attempt to map the whole world and instead looking for where two random paths cross, the cayleyR software can solve TopSpin puzzles with 20 tokens in just a few seconds. It's a reminder that sometimes, in a giant maze, you don't need to know every turn; you just need to find a place where two wandering paths happen to meet. The software is free and available for anyone to try, though the author warns that while it finds solutions quickly, it doesn't always find the perfect one.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →