Prolog,219字节
不,这不是打高尔夫球的语言。但我认为该站点需要更多Prolog。
s(N,N,N,79).
s(R,R,_,92).
s(R,C,N,47):-R+C=:=2*N.
s(N,_,N,45).
s(_,N,N,124).
s(_,_,_,32).
c(_,C,N):-C>2*N,nl.
c(R,C,N):-s(R,C,N,S),put(S),X is C+1,c(R,X,N).
r(R,N):-R>2*N.
r(R,N):-c(R,0,N),X is R+1,r(X,N).
g(N):-r(0,N).
swipl
在Linux上进行了测试。调用像这样:swipl -s asciiSun.prolog
; 然后查询您想要的太阳大小:
?- g(3).
\ | /
\ | /
\|/
---O---
/|\
/ | \
/ | \
true .
取消高尔夫:
% Args to sym/4 are row, column, N and the character code to be output at that location.
sym(N,N,N,79).
sym(R,R,_,'\\').
sym(R,C,N,'/') :- R+C =:= 2*N.
sym(N,_,N,'-').
sym(_,N,N,'|').
sym(_,_,_,' ').
% Args to putCols/3 are row, column, and N.
% Recursively outputs the characters in row from col onward.
putCols(_,C,N) :- C > 2*N, nl.
putCols(R,C,N) :- sym(R,C,N,S), put_code(S), NextC is C+1, putCols(R,NextC,N).
% Args to putRows/2 are row and N.
% Recursively outputs the grid from row downward.
putRows(R,N) :- R > 2*N.
putRows(R,N) :- putCols(R,0,N), NextR is R+1, putRows(NextR,N).
putGrid(N) :- putRows(0,N).
N=0
。