Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,135 @@
|
|||
' version 08-10-2016
|
||||
' compile with: fbc -s console
|
||||
|
||||
Data "00000000000000000000000000000000"
|
||||
Data "01111111110000000111111110000000"
|
||||
Data "01110001111000001111001111000000"
|
||||
Data "01110000111000001110000111000000"
|
||||
Data "01110001111000001110000000000000"
|
||||
Data "01111111110000001110000000000000"
|
||||
Data "01110111100000001110000111000000"
|
||||
Data "01110011110011101111001111011100"
|
||||
Data "01110001111011100111111110011100"
|
||||
Data "00000000000000000000000000000000"
|
||||
Data "END"
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As UInteger x, y, m, n
|
||||
Dim As String input_str
|
||||
|
||||
Do ' find out how big it is
|
||||
Read input_str
|
||||
If input_str = "END" Then Exit Do
|
||||
If x < Len(input_str) Then x = Len(input_str)
|
||||
y = y + 1
|
||||
Loop
|
||||
|
||||
m = x -1 : n = y -1
|
||||
ReDim As UByte old(m, n), new_(m, n)
|
||||
|
||||
y = 0
|
||||
Restore ' restore data pointer
|
||||
Do ' put data in array
|
||||
Read input_str
|
||||
If input_str="END" Then Exit Do
|
||||
For x = 0 To Len(input_str) -1
|
||||
old(x,y) = input_str[x] - Asc("0")
|
||||
' print image
|
||||
If old(x, y) = 0 Then Print "."; Else Print "#";
|
||||
Next
|
||||
Print
|
||||
y = y + 1
|
||||
Loop
|
||||
|
||||
'corners and sides do not change
|
||||
For x = 0 To m
|
||||
new_(x, 0) = old(x, 0)
|
||||
new_(x, n) = old(x, n)
|
||||
Next
|
||||
|
||||
For y = 0 To n
|
||||
new_(0, y) = old(0, y)
|
||||
new_(m, y) = old(m, y)
|
||||
Next
|
||||
|
||||
Dim As UInteger tmp, change, stage = 1
|
||||
Do
|
||||
change = 0
|
||||
For y = 1 To n -1
|
||||
For x = 1 To m -1
|
||||
' -1-
|
||||
If old(x,y) = 0 Then ' first condition, p1 must be black
|
||||
new_(x,y) = 0
|
||||
Continue For
|
||||
End If
|
||||
' -2-
|
||||
tmp = old(x, y -1) + old(x +1, y -1)
|
||||
tmp = tmp + old(x +1, y) + old(x +1, y +1) + old(x, y +1)
|
||||
tmp = tmp + old(x -1, y +1) + old(x -1, y) + old(x -1, y -1)
|
||||
If tmp < 2 OrElse tmp > 6 Then ' 2 <= B(p1) <= 6
|
||||
new_(x, y) = 1
|
||||
Continue For
|
||||
End If
|
||||
' -3-
|
||||
tmp = 0
|
||||
If old(x , y ) = 0 And old(x , y -1) = 1 Then tmp += 1 ' p1 > p2
|
||||
If old(x , y -1) = 0 And old(x +1, y -1) = 1 Then tmp += 1 ' p2 > p3
|
||||
If old(x +1, y -1) = 0 And old(x +1, y ) = 1 Then tmp += 1 ' p3 > p4
|
||||
If old(x +1, y ) = 0 And old(x +1, y +1) = 1 Then tmp += 1 ' p4 > p5
|
||||
If old(x +1, y +1) = 0 And old(x , y +1) = 1 Then tmp += 1 ' p5 > p6
|
||||
If old(x , y +1) = 0 And old(x -1, y +1) = 1 Then tmp += 1 ' p6 > p7
|
||||
If old(x -1, y +1) = 0 And old(x -1, y ) = 1 Then tmp += 1 ' p7 > p8
|
||||
If old(x -1, y ) = 0 And old(x -1, y -1) = 1 Then tmp += 1 ' p8 > p9
|
||||
If old(x -1, y -1) = 0 And old(x , y -1) = 1 Then tmp += 1 ' p9 > p2
|
||||
' tmp = 1 ==> A(P1) = 1
|
||||
If tmp <> 1 Then
|
||||
new_(x, y) = 1
|
||||
Continue For
|
||||
End If
|
||||
If (stage And 1) = 1 Then
|
||||
' step 1 -4- -5-
|
||||
If (old(x, y -1) + old(x +1, y) + old(x, y +1)) = 3 OrElse _
|
||||
(old(x +1, y) + old(x, y +1) + old(x -1, y)) = 3 Then
|
||||
new_(x, y) = 1
|
||||
Continue For
|
||||
End If
|
||||
Else
|
||||
' step 2 -4- -5-
|
||||
If (old(x, y -1) + old(x +1, y) + old(x -1, y)) = 3 OrElse _
|
||||
(old(x, y -1) + old(x, y +1) + old(x -1, y)) = 3 Then
|
||||
new_(x, y) = 1
|
||||
Continue For
|
||||
End If
|
||||
End If
|
||||
' all condition are met, make p1 white (0)
|
||||
new_(x, y) = 0
|
||||
change = 1 ' flag change
|
||||
Next
|
||||
Next
|
||||
|
||||
' copy new_() into old()
|
||||
For y = 0 To n
|
||||
For x = 0 To m
|
||||
old(x, y) = new_(x, y)
|
||||
Next
|
||||
Next
|
||||
|
||||
stage += 1
|
||||
Loop Until change = 0 ' stop when there are no changes made
|
||||
|
||||
Print ' print result
|
||||
Print "End result"
|
||||
For y = 0 To n
|
||||
For x = 0 To m
|
||||
If old(x, y) = 0 Then Print "."; Else Print "#";
|
||||
Next
|
||||
Print
|
||||
Next
|
||||
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
constant n = {{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0}};
|
||||
|
||||
function AB(sequence text, integer y, x, step)
|
||||
integer wtb = 0, bn = 0
|
||||
integer prev = '#', next
|
||||
string p2468 = ""
|
||||
for i=1 to length(n) do
|
||||
next = text[y+n[i][1]][x+n[i][2]]
|
||||
wtb += (prev='.' and next<='#')
|
||||
bn += (i>1 and next<='#')
|
||||
if and_bits(i,1)=0 then p2468 = append(p2468,prev) end if
|
||||
prev = next
|
||||
end for
|
||||
if step=2 then -- make it p6842
|
||||
p2468 = p2468[3..4]&p2468[1..2]
|
||||
end if
|
||||
return {wtb,bn,p2468}
|
||||
end function
|
||||
|
||||
procedure Zhang_Suen(sequence text)
|
||||
integer wtb, bn, changed, changes
|
||||
string p2468 -- (p6842 for step 2)
|
||||
text = split(text,'\n')
|
||||
while 1 do
|
||||
changed = 0
|
||||
for step=1 to 2 do
|
||||
changes = 0
|
||||
for y=2 to length(text)-1 do
|
||||
for x=2 to length(text[y])-1 do
|
||||
if text[y][x]='#' then
|
||||
{wtb,bn,p2468} = AB(text,y,x,step)
|
||||
if wtb=1
|
||||
and bn>=2 and bn<=6
|
||||
and find('.',p2468[1..3])
|
||||
and find('.',p2468[2..4])then
|
||||
changes = 1
|
||||
text[y][x] = '!' -- (logically still black)
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
end for
|
||||
if changes then
|
||||
for y=2 to length(text)-1 do
|
||||
text[y] = substitute(text[y],"!",".")
|
||||
end for
|
||||
changed = 1
|
||||
end if
|
||||
end for
|
||||
if not changed then exit end if
|
||||
end while
|
||||
puts(1,join(text,"\n"))
|
||||
end procedure
|
||||
|
||||
string small_rc = """
|
||||
................................
|
||||
.#########.......########.......
|
||||
.###...####.....####..####......
|
||||
.###....###.....###....###......
|
||||
.###...####.....###.............
|
||||
.#########......###.............
|
||||
.###.####.......###....###......
|
||||
.###..####..###.####..####.###..
|
||||
.###...####.###..########..###..
|
||||
................................"""
|
||||
Zhang_Suen(small_rc)
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
class ZhangSuen(str, black="1") {
|
||||
const NEIGHBOURS = [[-1,0],[-1,1],[0,1],[1,1],[1,0],[1,-1],[0,-1],[-1,-1]] # 8 neighbors
|
||||
const CIRCULARS = (NEIGHBOURS + [NEIGHBOURS.first]) # P2, ... P9, P2
|
||||
|
||||
has r = 0;
|
||||
has image = [[]];
|
||||
|
||||
method init {
|
||||
var s1 = str.lines.map{|line| line.chars.map{|c| c==black ? 1 : 0 }}
|
||||
var s2 = s1.len.of { s1[0].len.of(0) }
|
||||
var xr = RangeNum(1, s1.end-1)
|
||||
var yr = RangeNum(1, s1[0].end-1)
|
||||
do {
|
||||
r = 0;
|
||||
xr.each{|x| yr.each{|y| s2[x][y] = (s1[x][y] - self.zs(s1,x,y,1)) }} # Step 1
|
||||
xr.each{|x| yr.each{|y| s1[x][y] = (s2[x][y] - self.zs(s2,x,y,0)) }} # Step 2
|
||||
} while !r.is_zero;
|
||||
image = s1;
|
||||
}
|
||||
|
||||
method zs(ng,x,y,g) {
|
||||
(ng[x][y] == 0) ->
|
||||
|| (ng[x-1][y] + ng[x][y+1] + ng[x+g][y+g - 1] == 3) ->
|
||||
|| (ng[x+g - 1][y+g] + ng[x+1][y] + ng[x][y-1] == 3) ->
|
||||
&& return 0;
|
||||
|
||||
var bp1 = NEIGHBOURS.map {|p| ng[x+p[0]][y+p[1]] }.sum(0); # B(P1)
|
||||
return 0 if ((bp1 < 2) || (6 < bp1));
|
||||
|
||||
var ap1 = 0;
|
||||
CIRCULARS.map {|p| ng[x+p[0]][y+p[1]] }.each_cons(2, {|p|
|
||||
++ap1 if (p[0] < p[1]) # A(P1)
|
||||
})
|
||||
|
||||
return 0 if (ap1 != 1);
|
||||
r = 1
|
||||
}
|
||||
|
||||
method display {
|
||||
image.each{|row| say row.map{|col| col ? '#' : ' ' }.join }
|
||||
}
|
||||
}
|
||||
|
||||
var text = <<EOS
|
||||
00000000000000000000000000000000
|
||||
01111111110000000111111110000000
|
||||
01110001111000001111001111000000
|
||||
01110000111000001110000111000000
|
||||
01110001111000001110000000000000
|
||||
01111111110000001110000000000000
|
||||
01110111100000001110000111000000
|
||||
01110011110011101111001111011100
|
||||
01110001111011100111111110011100
|
||||
00000000000000000000000000000000
|
||||
EOS
|
||||
|
||||
ZhangSuen.new(text, black: "1").display
|
||||
Loading…
Add table
Add a link
Reference in a new issue