Templates / Implement recursive algorithms with sub-workflows: Towers of Hanoi demo

Implement recursive algorithms with sub-workflows: Towers of Hanoi demo

Ready for 3.0

by Adrian · 256 views · created 2025-09-16 · Engineering, Multimodal AI

Ready for 3.0. This template uses no nodes that n8n 3.0 removes. No removed nodes, versions or helpers found. Static check, last run 2026-12-01.

📬 Weekly n8n 3.0 breakage alerts, free

What this workflow does

This workflow has 13 nodes and runs manually, when you click “Execute workflow” (plus 1 other trigger). It uses only n8n's built-in nodes.

How it runs

Trigger: Manually, when you click “Execute workflow” (plus 1 other trigger).

  1. Set number of discs (Edit Fields (Set)): sets 1 field: numberOfDiscs
  2. Max 1 disc (If): checks a condition and branches into true / false
  3. Create stacks (Code): runs custom JavaScript code
  4. X to Z (Code): runs custom JavaScript code
  5. X Z Y (Execute Sub-workflow): calls another n8n workflow
  6. A B C (Execute Sub-workflow): calls another n8n workflow
  7. Update (Code): runs custom JavaScript code
  8. Solution (Code): runs custom JavaScript code
  9. X to Z (Code): runs custom JavaScript code
  10. Y X Z (Execute Sub-workflow): calls another n8n workflow

…plus 1 more step. See the full node list below.

Before you upgrade to n8n 3.0

Nothing in this workflow is removed in n8n 3.0, so it should import and run after the upgrade.

Check at runtime on n8n 3.0
  • Code node: the task timeout drops from 300s to 60s. Test with a realistic data volume.
Informational: a static scan can't see the data, so test these on your own instance. Status above is unchanged.

Nodes used (6)

From the author

How it works This is an example of using sub-workflow nodes and a proof of concept showing that it’s possible to solve and explain recursive problems with n8n. Towers of Hanoi - Task Move a stack of n disks from rod A to rod C, using rod B as auxiliary. Only…

Excerpt from Adrian's description on n8n.io.

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.