Warning, /frameworks/syntax-highlighting/autotests/input/highlight.exu is written in an unsupported language. File is not indexed.
0001 -- Test file for Kate's Euphoria syntax highlighting/code folding. 0002 -- BEGIN region marker test 0003 0004 -- code here 0005 0006 -- END region marker test 0007 0008 -- The N Queens Problem: 0009 -- Place N Queens on an NxN chess board 0010 -- such that they don't threaten each other. 0011 constant N = 8 -- try some other sizes 0012 constant ROW = 1, COLUMN = 2 0013 constant TRUE = 1, FALSE = 0 0014 type square(sequence x) 0015 -- a square on the board 0016 return length(x) = 2 0017 end type 0018 type row(integer x) 0019 -- a row on the board 0020 return x >= 1 and x <= N 0021 end type 0022 0023 function threat(square q1, square q2) 0024 -- do two queens threaten each other? 0025 if q1[COLUMN] = q2[COLUMN] then 0026 return TRUE 0027 elsif q1[ROW] - q1[COLUMN] = q2[ROW] - q2[COLUMN] then 0028 return TRUE 0029 elsif q1[ROW] + q1[COLUMN] = q2[ROW] + q2[COLUMN] then 0030 return TRUE 0031 elsif q1[ROW] = q2[ROW] then 0032 return TRUE 0033 else 0034 return FALSE 0035 end if 0036 end function 0037 0038 function conflict(square q, sequence queens) 0039 -- Would square p cause a conflict with other queens on board so far? 0040 for i = 1 to length(queens) do 0041 if threat(q, queens[i]) then 0042 return TRUE 0043 end if 0044 end for 0045 return FALSE 0046 end function 0047 0048 integer soln 0049 soln = 0 -- solution number 0050 0051 procedure print_board(sequence queens) 0052 -- print a solution, showing the Queens on the board 0053 integer k 0054 position(1, 1) 0055 printf(1, "Solution #%d\n\n ", soln) 0056 for c = 'a' to 'a' + N - 1 do 0057 printf(1, "%2s", c) 0058 end for 0059 puts(1, "\n") 0060 for r = 1 to N do 0061 printf(1, "%2d ", r) 0062 for c = 1 to N do 0063 if find({r,c}, queens) then 0064 puts(1, "Q ") 0065 else 0066 puts(1, ". ") 0067 end if 0068 end for 0069 puts(1, "\n") 0070 end for 0071 puts(1, "\nPress Enter. (q to quit) ") 0072 while TRUE do 0073 k = get_key() 0074 if k = 'q' then 0075 abort(0) 0076 elsif k != -1 then 0077 exit 0078 end if 0079 end while 0080 end procedure 0081 0082 procedure place_queen(sequence queens) 0083 -- place queens on a NxN chess board 0084 -- (recursive procedure) 0085 row r -- only need to consider one row for each queen 0086 if length(queens) = N then 0087 soln += 1 0088 print_board(queens) 0089 return 0090 end if 0091 r = length(queens)+1 0092 for c = 1 to N do 0093 if not conflict({r,c}, queens) then 0094 place_queen(append(queens, {r,c})) 0095 end if 0096 end for 0097 end procedure