#!sapphire
%行列で扱いやすいように#=-1, .=0 とした。
%扱いやすいように範囲外を-1として6*8行列とした。
def mat #m[[-1,-1,-1,-1,-1,-1,-1,-1],
[-1,-1,-1, 0, 0,-1,-1,-1],
[-1,-1, 0,-1,-1,-1, 0,-1],
[-1,-1,-1,-1, 0,-1, 0,-1],
[-1, 0, 0, 0,-1,-1,-1,-1],
[-1,-1,-1,-1,-1,-1,-1,-1]];
%等価なラベルをリストとして記憶する。
def equal [];
%(i,j)の周辺を含む9か所をマークする。等価なラベルが見つかった場合には記憶する。
def mark(i,j,v)
let(s,0)(t,0)
for(s:=i-1,s<=i+1,s++)
for(t:=j-1,t<=j+1,t++)
if(mat[s,t] = 0)
mat[s,t] := v
else if(mat[s,t] < v && positive?(mat[s,t]))
equal := cons(list(v,mat[s,t]),equal)
else
#f;
%走査し等価なラベル分を差し引いて空間数を表示する。
def scan()
let(i,0)(j,0)(n,0){
for(i:=2,i<=5,i++)
for(j:=2,j<=7,j++)
if(mat[i,j] = 0){
n++,
mark(i,j,n)}
else if(mat[i,j] >= 1)
mark(i,j,mat[i,j])
else
#f,
answer(n)};
def answer(n){
display(n-length(equal)),
newline(),
display(equal),
newline(),
display(mat)};
norm> scan();
3
((4 3))
#m((-1 -1 -1 -1 -1 -1 -1 -1)(-1 -1 -1 1 1 -1 -1 -1)(-1 -1 1 -1 -1 -1 2 -1)(-1 -1 -1 -1 3 -1 2 -1)(-1 4 4 3 -1 -1 -1 -1)(-1 -1 -1 -1 -1 -1 -1 -1))#<undef>
norm>
IyFzYXBwaGlyZQol6KGM5YiX44Gn5omx44GE44KE44GZ44GE44KI44GG44GrIz0tMSwgLj0wIOOBqOOBl+OBn+OAggol5omx44GE44KE44GZ44GE44KI44GG44Gr56+E5Zuy5aSW44KSLTHjgajjgZfjgaY2KjjooYzliJfjgajjgZfjgZ/jgIIKZGVmIG1hdCAjbVtbLTEsLTEsLTEsLTEsLTEsLTEsLTEsLTFdLAogICAgICAgICAgIFstMSwtMSwtMSwgMCwgMCwtMSwtMSwtMV0sIAogICAgICAgICAgIFstMSwtMSwgMCwtMSwtMSwtMSwgMCwtMV0sIAogICAgICAgICAgIFstMSwtMSwtMSwtMSwgMCwtMSwgMCwtMV0sIAogICAgICAgICAgIFstMSwgMCwgMCwgMCwtMSwtMSwtMSwtMV0sCiAgICAgICAgICAgWy0xLC0xLC0xLC0xLC0xLC0xLC0xLC0xXV07Cgol562J5L6h44Gq44Op44OZ44Or44KS44Oq44K544OI44Go44GX44Gm6KiY5oa244GZ44KL44CCCmRlZiBlcXVhbCBbXTsKCiUoaSxqKeOBruWRqOi+uuOCkuWQq+OCgDnjgYvmiYDjgpLjg57jg7zjgq/jgZnjgovjgILnrYnkvqHjgarjg6njg5njg6vjgYzopovjgaTjgYvjgaPjgZ/loLTlkIjjgavjga/oqJjmhrbjgZnjgovjgIIKZGVmIG1hcmsoaSxqLHYpCiAgbGV0KHMsMCkodCwwKQogICAgZm9yKHM6PWktMSxzPD1pKzEscysrKQogICAgICBmb3IodDo9ai0xLHQ8PWorMSx0KyspCiAgICAgICAgaWYobWF0W3MsdF0gPSAwKQogICAgICAgICAgbWF0W3MsdF0gOj0gdgogICAgICAgIGVsc2UgaWYobWF0W3MsdF0gPCB2ICYmIHBvc2l0aXZlPyhtYXRbcyx0XSkpIAogICAgICAgICAgZXF1YWwgOj0gY29ucyhsaXN0KHYsbWF0W3MsdF0pLGVxdWFsKQogICAgICAgIGVsc2UKICAgICAgICAgICNmOwoKCiXotbDmn7vjgZfnrYnkvqHjgarjg6njg5njg6vliIbjgpLlt67jgZflvJXjgYTjgabnqbrplpPmlbDjgpLooajnpLrjgZnjgovjgIIKZGVmIHNjYW4oKQogIGxldChpLDApKGosMCkobiwwKXsKICAgIGZvcihpOj0yLGk8PTUsaSsrKQogICAgICBmb3Ioajo9MixqPD03LGorKykKICAgICAgICBpZihtYXRbaSxqXSA9IDApewogICAgICAgICAgbisrLAogICAgICAgICAgbWFyayhpLGosbil9CiAgICAgICAgZWxzZSBpZihtYXRbaSxqXSA+PSAxKQogICAgICAgICAgbWFyayhpLGosbWF0W2ksal0pCiAgICAgICAgZWxzZQogICAgICAgICAgI2YsCiAgYW5zd2VyKG4pfTsKICAgCgpkZWYgYW5zd2VyKG4pewogIGRpc3BsYXkobi1sZW5ndGgoZXF1YWwpKSwKICBuZXdsaW5lKCksCiAgZGlzcGxheShlcXVhbCksCiAgbmV3bGluZSgpLAogIGRpc3BsYXkobWF0KX07CiAgICAKICAgICAgICAgICAgIApub3JtPiBzY2FuKCk7CjMKKCg0IDMpKQojbSgoLTEgLTEgLTEgLTEgLTEgLTEgLTEgLTEpKC0xIC0xIC0xIDEgMSAtMSAtMSAtMSkoLTEgLTEgMSAtMSAtMSAtMSAyIC0xKSgtMSAtMSAtMSAtMSAzIC0xIDIgLTEpKC0xIDQgNCAzIC0xIC0xIC0xIC0xKSgtMSAtMSAtMSAtMSAtMSAtMSAtMSAtMSkpIzx1bmRlZj4Kbm9ybT4g
Main.java:1: error: illegal character: '#'
#!sapphire
^
Main.java:1: error: class, interface, or enum expected
#!sapphire
^
Main.java:2: error: illegal character: '#'
%???????????#=-1, .=0 ????
^
Main.java:2: error: illegal character: '\u3002'
%???????????#=-1, .=0 ????
^
Main.java:3: error: illegal character: '\u3002'
%????????????-1???6*8??????
^
Main.java:4: error: illegal character: '#'
def mat #m[[-1,-1,-1,-1,-1,-1,-1,-1],
^
Main.java:11: error: class, interface, or enum expected
%??????????????????
^
Main.java:11: error: illegal character: '\u3002'
%??????????????????
^
Main.java:14: error: class, interface, or enum expected
%(i,j)??????9??????????????????????????????
^
Main.java:14: error: illegal character: '\u3002'
%(i,j)??????9??????????????????????????????
^
Main.java:14: error: illegal character: '\u3002'
%(i,j)??????9??????????????????????????????
^
Main.java:24: error: illegal character: '#'
#f;
^
Main.java:27: error: class, interface, or enum expected
%?????????????????????????
^
Main.java:27: error: illegal character: '\u3002'
%?????????????????????????
^
Main.java:38: error: illegal character: '#'
#f,
^
Main.java:42: error: class, interface, or enum expected
def answer(n){
^
Main.java:50: error: class, interface, or enum expected
norm> scan();
^
Main.java:51: error: class, interface, or enum expected
3
^
Main.java:53: error: illegal character: '#'
#m((-1 -1 -1 -1 -1 -1 -1 -1)(-1 -1 -1 1 1 -1 -1 -1)(-1 -1 1 -1 -1 -1 2 -1)(-1 -1 -1 -1 3 -1 2 -1)(-1 4 4 3 -1 -1 -1 -1)(-1 -1 -1 -1 -1 -1 -1 -1))#<undef>
^
Main.java:53: error: illegal character: '#'
#m((-1 -1 -1 -1 -1 -1 -1 -1)(-1 -1 -1 1 1 -1 -1 -1)(-1 -1 1 -1 -1 -1 2 -1)(-1 -1 -1 -1 3 -1 2 -1)(-1 4 4 3 -1 -1 -1 -1)(-1 -1 -1 -1 -1 -1 -1 -1))#<undef>
^
20 errors