File: highlight.exu.html

package info (click to toggle)
kf6-syntax-highlighting 6.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 47,568 kB
  • sloc: xml: 197,750; cpp: 12,850; python: 3,023; sh: 955; perl: 546; ruby: 488; pascal: 393; javascript: 161; php: 150; jsp: 132; lisp: 131; haskell: 124; ada: 119; ansic: 107; makefile: 96; f90: 94; ml: 85; cobol: 81; yacc: 71; csh: 62; erlang: 54; sql: 51; java: 47; objc: 37; awk: 31; asm: 30; tcl: 29; fortran: 18; cs: 10
file content (104 lines) | stat: -rw-r--r-- 8,629 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>highlight.exu</title>
<meta name="generator" content="KF5::SyntaxHighlighting - Definition (Euphoria) - Theme (Breeze Light)"/>
</head><body style="background-color:#ffffff;color:#1f1c1b"><pre>
<span style="color:#898887">-- Test file for Kate's Euphoria syntax highlighting/code folding.</span>
<span style="color:#0057ae;background-color:#e0e9f8">-- BEGIN region marker test</span>

<span style="color:#898887">-- code here</span>

<span style="color:#0057ae;background-color:#e0e9f8">-- END region marker test</span>

<span style="color:#898887">-- The N Queens Problem:</span>
<span style="color:#898887">-- Place N Queens on an NxN chess board</span>
<span style="color:#898887">-- such that they don't threaten each other.</span>
<span style="color:#0057ae">constant</span> N = <span style="color:#b08000">8</span> <span style="color:#898887">-- try some other sizes</span>
<span style="color:#0057ae">constant</span> ROW = <span style="color:#b08000">1</span>, COLUMN = <span style="color:#b08000">2</span>
<span style="color:#0057ae">constant</span> <span style="font-weight:bold">TRUE</span> = <span style="color:#b08000">1</span>, <span style="font-weight:bold">FALSE</span> = <span style="color:#b08000">0</span>
<span style="font-weight:bold">type</span> square(<span style="color:#0057ae">sequence</span> x)
<span style="color:#898887">-- a square on the board</span>
    <span style="font-weight:bold">return</span> <span style="font-weight:bold">length</span>(x) = <span style="color:#b08000">2</span>
<span style="font-weight:bold">end type</span>
<span style="font-weight:bold">type</span> row(<span style="color:#0057ae">integer</span> x)
<span style="color:#898887">-- a row on the board</span>
    <span style="font-weight:bold">return</span> x >= <span style="color:#b08000">1</span> <span style="font-weight:bold">and</span> x &lt;= N
<span style="font-weight:bold">end type</span>

<span style="font-weight:bold">function</span> threat(square q1, square q2)
<span style="color:#898887">-- do two queens threaten each other?</span>
    <span style="font-weight:bold">if</span> q1[COLUMN] = q2[COLUMN] <span style="font-weight:bold">then</span>
 <span style="font-weight:bold">return</span> <span style="font-weight:bold">TRUE</span>
    <span style="font-weight:bold">elsif</span> q1[ROW] - q1[COLUMN] = q2[ROW] - q2[COLUMN] <span style="font-weight:bold">then</span>
 <span style="font-weight:bold">return</span> <span style="font-weight:bold">TRUE</span>
    <span style="font-weight:bold">elsif</span> q1[ROW] + q1[COLUMN] = q2[ROW] + q2[COLUMN] <span style="font-weight:bold">then</span>
 <span style="font-weight:bold">return</span> <span style="font-weight:bold">TRUE</span>
    <span style="font-weight:bold">elsif</span> q1[ROW] = q2[ROW] <span style="font-weight:bold">then</span>
 <span style="font-weight:bold">return</span> <span style="font-weight:bold">TRUE</span>
    <span style="font-weight:bold">else</span>
 <span style="font-weight:bold">return</span> <span style="font-weight:bold">FALSE</span>
    <span style="font-weight:bold">end if</span>
<span style="font-weight:bold">end function</span>

<span style="font-weight:bold">function</span> conflict(square q, <span style="color:#0057ae">sequence</span> queens)
<span style="color:#898887">-- Would square p cause a conflict with other queens on board so far?</span>
    <span style="font-weight:bold">for</span> i = <span style="color:#b08000">1</span> <span style="font-weight:bold">to</span> <span style="font-weight:bold">length</span>(queens) <span style="font-weight:bold">do</span>
 <span style="font-weight:bold">if</span> threat(q, queens[i]) <span style="font-weight:bold">then</span>
     <span style="font-weight:bold">return</span> <span style="font-weight:bold">TRUE</span>
 <span style="font-weight:bold">end if</span>
    <span style="font-weight:bold">end for</span>
    <span style="font-weight:bold">return</span> <span style="font-weight:bold">FALSE</span>
<span style="font-weight:bold">end function</span>

<span style="color:#0057ae">integer</span> soln
soln = <span style="color:#b08000">0</span> <span style="color:#898887">-- solution number</span>

<span style="font-weight:bold">procedure</span> print_board(<span style="color:#0057ae">sequence</span> queens)
<span style="color:#898887">-- print a solution, showing the Queens on the board</span>
    <span style="color:#0057ae">integer</span> k
    <span style="font-weight:bold">position</span>(<span style="color:#b08000">1</span>, <span style="color:#b08000">1</span>)
    <span style="font-weight:bold">printf</span>(<span style="color:#b08000">1</span>, <span style="color:#bf0303">"Solution #%d\n\n  "</span>, soln)
    <span style="font-weight:bold">for</span> c = 'a' <span style="font-weight:bold">to</span> 'a' + N - <span style="color:#b08000">1</span> <span style="font-weight:bold">do</span>
 <span style="font-weight:bold">printf</span>(<span style="color:#b08000">1</span>, <span style="color:#bf0303">"%2s"</span>, c)
    <span style="font-weight:bold">end for</span>
    <span style="font-weight:bold">puts</span>(<span style="color:#b08000">1</span>, <span style="color:#bf0303">"\n"</span>)
    <span style="font-weight:bold">for</span> r = <span style="color:#b08000">1</span> <span style="font-weight:bold">to</span> N <span style="font-weight:bold">do</span>
 <span style="font-weight:bold">printf</span>(<span style="color:#b08000">1</span>, <span style="color:#bf0303">"%2d "</span>, r)
 <span style="font-weight:bold">for</span> c = <span style="color:#b08000">1</span> <span style="font-weight:bold">to</span> N <span style="font-weight:bold">do</span>
     <span style="font-weight:bold">if</span> <span style="font-weight:bold">find</span>({r,c}, queens) <span style="font-weight:bold">then</span>
  <span style="font-weight:bold">puts</span>(<span style="color:#b08000">1</span>, <span style="color:#bf0303">"Q "</span>)
     <span style="font-weight:bold">else</span>
  <span style="font-weight:bold">puts</span>(<span style="color:#b08000">1</span>, <span style="color:#bf0303">". "</span>)
     <span style="font-weight:bold">end if</span>
 <span style="font-weight:bold">end for</span>
 <span style="font-weight:bold">puts</span>(<span style="color:#b08000">1</span>, <span style="color:#bf0303">"\n"</span>)
    <span style="font-weight:bold">end for</span>
    <span style="font-weight:bold">puts</span>(<span style="color:#b08000">1</span>, <span style="color:#bf0303">"\nPress Enter. (q to quit) "</span>)
    <span style="font-weight:bold">while</span> <span style="font-weight:bold">TRUE</span> <span style="font-weight:bold">do</span>
 k = <span style="font-weight:bold">get_key</span>()
 <span style="font-weight:bold">if</span> k = 'q' <span style="font-weight:bold">then</span>
     <span style="font-weight:bold">abort</span>(<span style="color:#b08000">0</span>)
 <span style="font-weight:bold">elsif</span> k != -<span style="color:#b08000">1</span> <span style="font-weight:bold">then</span>
     <span style="font-weight:bold">exit</span>
 <span style="font-weight:bold">end if</span>
    <span style="font-weight:bold">end while</span>
<span style="font-weight:bold">end procedure</span>

<span style="font-weight:bold">procedure</span> place_queen(<span style="color:#0057ae">sequence</span> queens)
<span style="color:#898887">-- place queens on a NxN chess board</span>
<span style="color:#898887">-- (recursive procedure)</span>
    row r <span style="color:#898887">-- only need to consider one row for each queen</span>
    <span style="font-weight:bold">if</span> <span style="font-weight:bold">length</span>(queens) = N <span style="font-weight:bold">then</span>
 soln += <span style="color:#b08000">1</span>
 print_board(queens)
 <span style="font-weight:bold">return</span>
    <span style="font-weight:bold">end if</span>
    r = <span style="font-weight:bold">length</span>(queens)+<span style="color:#b08000">1</span>
    <span style="font-weight:bold">for</span> c = <span style="color:#b08000">1</span> <span style="font-weight:bold">to</span> N <span style="font-weight:bold">do</span>
 <span style="font-weight:bold">if</span> <span style="font-weight:bold">not</span> conflict({r,c}, queens) <span style="font-weight:bold">then</span>
     place_queen(<span style="font-weight:bold">append</span>(queens, {r,c}))
 <span style="font-weight:bold">end if</span>
    <span style="font-weight:bold">end for</span>
<span style="font-weight:bold">end procedure</span>
</pre></body></html>