Code Monkey home page Code Monkey logo

go-hanoi's Introduction

Go-Hanoi

The famous Hanoi game written in Go. To test some configurations, from a shell:

go get github.com/skelterjohn/go.matrix
git clone https://github.com/made2591/go-hanoi
cd go-hanoi
go run main.go

Moves will be printed in stdout, with scores (number of) in the end. Below an execution gif with 6 disks:

Dependencies

The only external used is the following:

go get github.com/skelterjohn/go.matrix

Thanks to skelterjohn for his lib. I think I will contribute soon because I'm truly interested (see go-perceptron-go). I was just bored XD (this fu****ng tricky game drived me crazy), of course you can use primitive...

Notes about pretty print

It might seem easy to make a version of Hanoi in Go. And it is. My initial plan was to learn how to print in place multiline-string in go. Then problem became "how can I pretty print a generic Hanoi configuration?", such as [2, 1, 0]. After some tests, I realized that the best Hanoi representation is the matrix form.

So I looked for a matrix lib on github and found go.matrix to be good enought for my needs (just a easy/ready-to-use matrix representation). I think I will go throught this repository because I found some foundamentals missing (projections, max, sum, etc). Back to my problem...how could you define f([][]) to return strings like the one above?

|--------------------------|
|   **   |        |        |  
|  ****  |        |        |  
| ****** |        |        |  
|--------------------------|

|--------------------------|
|        |        |        |  
|        |        |   **   |  
| ****** |        |  ****  |  
|--------------------------|

|--------------------------------------|
|            |            |            |  
|            |            |            |  
|            |            |            |  
|  ********  |            |     **     |  
| ********** |   ******   |    ****    |  
|--------------------------------------|

The answer is simple: DON'T try to collapse positions and dimensions in one-dimensional struct. Instead, procede creating a matrix form with a drawcell function as defined above. With a little of linear algebra you should understand the logic behind: the point is find relations between average point, doubling disk dimension and user mean to center disk in columns (see func cell) and please feel free to ask.

Improvements

  • Realize a better-performance version of Hanoi solver if there are more than one auxiliary columns.
  • Introduce check-errors for setup (actually, index of columns are not cheked)

go-hanoi's People

Contributors

made2591 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.