diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch) | |
tree | 5ac38a06f3dde268dc7927dc155896926aaf7012 /kate/tests/highlight.exu | |
download | tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kate/tests/highlight.exu')
-rw-r--r-- | kate/tests/highlight.exu | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/kate/tests/highlight.exu b/kate/tests/highlight.exu new file mode 100644 index 000000000..3651adf33 --- /dev/null +++ b/kate/tests/highlight.exu @@ -0,0 +1,97 @@ +-- Test file for Kate's Euphoria syntax highlighting/code folding. +-- BEGIN region marker test + +-- code here + +-- END region marker test + +-- The N Queens Problem: +-- Place N Queens on an NxN chess board +-- such that they don't threaten each other. +constant N = 8 -- try some other sizes +constant ROW = 1, COLUMN = 2 +constant TRUE = 1, FALSE = 0 +type square(sequence x) +-- a square on the board + return length(x) = 2 +end type +type row(integer x) +-- a row on the board + return x >= 1 and x <= N +end type + +function threat(square q1, square q2) +-- do two queens threaten each other? + if q1[COLUMN] = q2[COLUMN] then + return TRUE + elsif q1[ROW] - q1[COLUMN] = q2[ROW] - q2[COLUMN] then + return TRUE + elsif q1[ROW] + q1[COLUMN] = q2[ROW] + q2[COLUMN] then + return TRUE + elsif q1[ROW] = q2[ROW] then + return TRUE + else + return FALSE + end if +end function + +function conflict(square q, sequence queens) +-- Would square p cause a conflict with other queens on board so far? + for i = 1 to length(queens) do + if threat(q, queens[i]) then + return TRUE + end if + end for + return FALSE +end function + +integer soln +soln = 0 -- solution number + +procedure print_board(sequence queens) +-- print a solution, showing the Queens on the board + integer k + position(1, 1) + printf(1, "Solution #%d\n\n ", soln) + for c = 'a' to 'a' + N - 1 do + printf(1, "%2s", c) + end for + puts(1, "\n") + for r = 1 to N do + printf(1, "%2d ", r) + for c = 1 to N do + if find({r,c}, queens) then + puts(1, "Q ") + else + puts(1, ". ") + end if + end for + puts(1, "\n") + end for + puts(1, "\nPress Enter. (q to quit) ") + while TRUE do + k = get_key() + if k = 'q' then + abort(0) + elsif k != -1 then + exit + end if + end while +end procedure + +procedure place_queen(sequence queens) +-- place queens on a NxN chess board +-- (recursive procedure) + row r -- only need to consider one row for each queen + if length(queens) = N then + soln += 1 + print_board(queens) + return + end if + r = length(queens)+1 + for c = 1 to N do + if not conflict({r,c}, queens) then + place_queen(append(queens, {r,c})) + end if + end for +end procedure |