diff --git a/test/ascii-art.nas b/test/ascii-art.nas index bcb99ed..94e70c9 100644 --- a/test/ascii-art.nas +++ b/test/ascii-art.nas @@ -128,6 +128,7 @@ var curve5=func() return; } trans_ttf("just for test"); +trans_ttf("ValKmjolnir"); curve1(); curve2(); curve3(); diff --git a/test/bfs.nas b/test/bfs.nas index f79ed57..2b5050e 100644 --- a/test/bfs.nas +++ b/test/bfs.nas @@ -20,7 +20,7 @@ var prt=func() s~=map[i][j]; s~='\n'; } - print(s); + print(s,'\n'); } var bfs=func(begin,end) @@ -50,7 +50,7 @@ var bfs=func(begin,end) } prt(); } - print("cannot reach."); + print("cannot reach.\n"); return; } diff --git a/test/bp.nas b/test/bp.nas index 2a15c0d..243da39 100644 --- a/test/bp.nas +++ b/test/bp.nas @@ -127,7 +127,7 @@ var backward=func(x) var cnt=0; var show=0; var error=1e8; -while(error>0.01) +while(error>0.0005) { error=0; for(var i=0;i<4;i+=1) @@ -138,13 +138,13 @@ while(error>0.01) } cnt+=1; show+=1; - if(show==100) + if(show==200) { show=0; - print('epoch ',cnt,':',error); + print('epoch ',cnt,':',error,'\r'); } } -print('\afinished.'); +print('finished after ',cnt,' epoch.\n'); var vec=[ [0,0], [0,1], @@ -154,5 +154,5 @@ var vec=[ foreach(var v;vec) { run(v); - print(v,': ',output[0].out); + print(v,': ',output[0].out,'\n'); } \ No newline at end of file diff --git a/test/leetcode1319.nas b/test/leetcode1319.nas new file mode 100644 index 0000000..a1e64e4 --- /dev/null +++ b/test/leetcode1319.nas @@ -0,0 +1,32 @@ +import("lib.nas"); +# 并查集 +var n=4; +var input=[[0,1],[0,2],[1,2]]; + +var find_root=func(x,parent) +{ + while(parent[x]!=nil) + x=parent[x]; + return x; +} +var union_root=func(x,y,parent) +{ + var x_root=find_root(x,parent); + var y_root=find_root(y,parent); + if(x_root==y_root) return 0; + else parent[x_root]=y_root; + return 1; +} +var makeConnect=func(n,connections) +{ + if(size(connections)