Floyd's triangle: Difference between revisions
→{{header|Picat}}: Moved into subsections.
(→{{header|Picat}}: Moved into subsections.) |
|||
Line 4,982:
=={{header|Picat}}==
===List comprehension===
<lang Picat>import util.
go =>▼
println("N=5:"),▼
println(floyd1(5)),▼
nl,▼
println("N=14:"), ▼
println(floyd2(14)),▼
nl.▼
% Calculate the numbers first and then format them
Line 4,996 ⟶ 4,989:
M = [[J+SS : J in 1..I] : I in 1..N, SS=sum(1..I-1)],
S = [slice(SS,2) : Row in M, SS = [to_fstring(to_fstring("%%%dd",M[N,I].to_string().length+1),E) :
{E,I} in zip(Row,1..Row.length)].join('')].join("\n").</lang>
===Loop based===
{{trans|Prolog}}
<lang Picat>
floyd2(N) = S =>
S = [],
Line 5,014 ⟶ 5,008:
end.</lang>
===Test===
<lang Picat>
▲go =>
▲ println("N=5:"),
▲ println(floyd1(5)),
▲ nl,
▲ println("N=14:"),
▲ println(floyd2(14)),
▲ nl.</lang>
{{out}}
<pre>N=5:
1
|