DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Thursday Code Puzzler: Solve the Towers of Hanoi

Thursday Code Puzzler: Solve the Towers of Hanoi

James Sugrue user avatar by
James Sugrue
CORE ·
Apr. 19, 12 · Java Zone · Interview
Like (0)
Save
Tweet
8.94K Views

Join the DZone community and get the full member experience.

Join For Free

Another Thursday, another puzzle. The idea is simple: solve the coding problem as efficiently as you can, in any language or framework that you think is suitable. Last week we got some great answers with Fabie, Christian and Francesco giving pretty detailed answers - thanks for participating guys. 

Note: Even though there really is nothing stopping you from finding a solution to this on the internet, try to keep honest, and come up with your own answer.  It's all about the participation!

Towers of Hanoi 

Let's go for another classic computer science coding problem, the Towers of Hanoi.  The objective is to move the entire stack to any other rod, obeying these rules: 

  • Only one disk can be moved at a time
  • Each move consists of taking the upper disk from one rod, adding it onto another rod, on top of any disks that you may have already placed on that rod.
  • But no disk can be placed on top of a smaller disk

There's a few different ways to achieve this. If you wish, you can express the efficiency of the algorithm you come up with using Big O notation.

Computer science Coding (social sciences) Express Efficiency (statistics) Framework Computer IT Internet (web browser) Algorithm

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Challenges to Designing Data Pipelines at Scale
  • What Is HttpSession in Servlets?
  • Why Performance Projects Fail
  • What Are Cookies in Servlets?

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo