tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
31
Task/Pascals-triangle/Oz/pascals-triangle.oz
Normal file
31
Task/Pascals-triangle/Oz/pascals-triangle.oz
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
declare
|
||||
fun {NextLine Xs}
|
||||
{List.zip 0|Xs {Append Xs [0]}
|
||||
fun {$ Left Right}
|
||||
Left + Right
|
||||
end}
|
||||
end
|
||||
|
||||
fun {Triangle N}
|
||||
{List.take {Iterate [1] NextLine} N}
|
||||
end
|
||||
|
||||
fun lazy {Iterate I F}
|
||||
I|{Iterate {F I} F}
|
||||
end
|
||||
|
||||
%% Only works nicely for N =< 5.
|
||||
proc {PrintTriangle T}
|
||||
N = {Length T}
|
||||
in
|
||||
for
|
||||
Line in T
|
||||
Indent in N-1..0;~1
|
||||
do
|
||||
for _ in 1..Indent do {System.printInfo " "} end
|
||||
for L in Line do {System.printInfo L#" "} end
|
||||
{System.printInfo "\n"}
|
||||
end
|
||||
end
|
||||
in
|
||||
{PrintTriangle {Triangle 5}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue