Towers of Hanoi from a Random Start

solve = go 3
where
go _ [] = []
go i (n : ns)
| n /= i = clear ++ [(1, i)] ++ stack
| otherwise = first (+ 1) <$> go i ns
where
aux = 6 - n - i
clear = first (+ 1) <$> go aux ns
stack = first (+ 1) <$> go i ((const aux) <$> ns)

--

--

--

Software engineer, volunteer K-12 math and computer science teacher, author of the CodeWorld platform, amateur ring theorist, and Haskell enthusiast.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Top-notch Ranked Wordpress Web hosting services for 2019

Collections of Sandbox

Collections of Sandbox

Python Flask Tutorial

Front End vs. Back End Explained For Non-Technical Entrepreneurs | TechSuite Blog

Why JAMstack approach instead of wordpress?

“Fundamentals, fundamentals, fundamentals…

Adding Cloudant search to your static Jekyll blog

VPC-native clusters on Google Kubernetes Engine

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chris Smith

Chris Smith

Software engineer, volunteer K-12 math and computer science teacher, author of the CodeWorld platform, amateur ring theorist, and Haskell enthusiast.

More from Medium

Graph Theory: Euler’s Theorem for Planar Graphs

The Simplest Math Problem We Still Can’t Solve — Part 3

Finance Part 3: How can we be financially stable?

Paul Dirac- Mathematics and Aesthetics