Pascal's triangle: Difference between revisions

→‎{{header|AppleScript}}: (Indentation of triangle lines)
(→‎{{header|AppleScript}}: (Indentation of triangle lines))
Line 278:
 
 
<lang AppleScript>on run
 
on run
set lstTriangle to pascal(7)
intercalate(linefeed, ¬
map(tabSpacedmClosure(spacedAndIndented, pascal(7)))¬
{lngWidth:(length of intercalate(" ", (item -1 of lstTriangle)))}), ¬
lstTriangle))
end run
 
Line 311 ⟶ 317:
 
-- [Text | Number] -> Text
on tabSpacedspacedAndIndented(lst)
set strLine to intercalate(tab" ", lst)
nreps(" ", ¬
end tabSpaced
((my closure's lngWidth) - (length of strLine)) / 2) & strLine
end spacedAndIndented
 
 
-- String -> Int -> String
on nreps(s, n)
set o to ""
if n < 1 then return o
repeat while (n > 1)
if (n mod 2) > 0 then set o to o & s
set n to (n div 2)
set s to (s & s)
end repeat
return o & s
end nreps
 
-- GENERIC LIBRARY FUNCTIONS
Line 330 ⟶ 351:
return v
end foldl
 
-- foldr :: (a -> b -> a) -> a -> [b] -> a
on foldr(f, startValue, xs)
set mf to mReturn(f)
set v to startValue
set lng to length of xs
repeat with i from lng to 1 by -1
set v to mf's lambda(v, item i of xs, i, xs)
end repeat
return v
end foldr
 
-- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
Line 383 ⟶ 416:
end script
end mReturn
 
-- Handler -> Record -> Script
on mClosure(f, recBindings)
script
property closure : recBindings
property lambda : f
end script
end mClosure
 
</lang>
 
 
{{Out}}
<pre> 1
1 1
1 1
1 2 1
1 2 1
1 3 3 1
1 3 3 1
1 4 6 4 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1</pre>
 
=={{header|AutoHotkey}}==
9,655

edits