Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* levelezősök
  + Adator. prog.
  + feladatsor
  + quick link

teaching assets


Félévek

* 2024/25/1
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

20120816a

8 queens

The 8 queens puzzle is the problem of placing 8 chess queens on an 8×8 chessboard so that no two queens threaten each other.

The exercise this time is to display "graphically" a possible setup. The chessboard is represented as an array (instead of a matrix), e.g. [7,3,0,2,5,1,6,4]. This means: in the 1st column a queen is located in the 8th row (from the bottom), in the 2nd column there is a queen in the 4th row, etc. (Indexation of rows starts with 0.) From this array we could display the following chessboard:

+-----------------+
| Q . . . . . . . |
| . . . . . . Q . |
| . . . . Q . . . |
| . . . . . . . Q |
| . Q . . . . . . |
| . . . Q . . . . |
| . . . . . Q . . |
| . . Q . . . . . |
+-----------------+

Exercise: write a method that receives a list of 8 elements, and draws the corresponding chessboard. For instance, if the input is [0,4,7,5,2,6,1,3], then draw the following chessboard:

+-----------------+
| . . Q . . . . . |
| . . . . . Q . . |
| . . . Q . . . . |
| . Q . . . . . . |
| . . . . . . . Q |
| . . . . Q . . . |
| . . . . . . Q . |
| Q . . . . . . . |
+-----------------+

Some important points:

  • The chessboard should look like a square (width = height).
  • Draw the frame too.
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2015 June 27, 11:56