Giter VIP home page Giter VIP logo

backtracking's Introduction

Bactrakcing algorithms

Some examples of backtracking algorithms implemented in Python

One to hundred

Fill a 10x10 board with 1 to 100 integers.

  1. Start by writing 1 where you want on the board.

  2. To write the next number, you must skip 2 cells in a straight line or one cell diagonally (any direction).

     * they are separated by 2 empty cells on a straight line :
         `10 . . 11`
     * or one cell diagonally :
         ```
         10 .  .
         .  .  .
         .  .  11
         ```
    
  3. Repeat last step untill you are strucked or have reached 100.

A solution found:

  1 43 70 16 42 65 11 41 64 10
 56100 34 55 99 31 52 98 30 51
 71 17 95 82 24 88 79 23 89 78
  2 44 69 15 35 66 12 40 63  9
 57 83 33 54 96 32 53 97 29 50
 72 18 94 81 25 87 80 22 90 77
  3 45 68 14 36 67 13 39 62  8
 58 84 26 47 85 27 48 86 28 49
 73 19 93 74 20 92 75 21 91 76
  4 46 59  5 37 60  6 38 61  7

N-Queens

Dispose N queens on a NxN chess board without any pair attacking each other.

A solution for 10 queens on a 10x10 board:


       a b c d e f g h i j
    10 ♛ . . . . . . . . .
     9 . . ♛ . . . . . . .
     8 . . . . . ♛ . . . .
     7 . . . . . . . ♛ . .
     6 . . . . . . . . . ♛
     5 . . . . ♛ . . . . .
     4 . . . . . . . . ♛ .
     3 . ♛ . . . . . . . .
     2 . . . ♛ . . . . . .
     1 . . . . . . ♛ . . .

backtracking's People

Contributors

qkzk avatar

Watchers

 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.