Pascal's triangle: Difference between revisions
Content deleted Content added
→{{header|AppleScript}}: Updated primitives and formatting |
|||
Line 277:
=={{header|AppleScript}}==
<lang AppleScript>-- pascal :: Int -> [[Int]]▼
▲-- pascal :: Int -> [[Int]]
on pascal(intRows)
script addRow
on nextRow(row)
script add
on lambda(a, b)
Line 300 ⟶ 296:
end script
end pascal
Line 309 ⟶ 305:
set lstTriangle to pascal(7)
script
on lambda(xs)
script rightAlign
intercalate("", map(rightAlign, xs))
end lambda
end script
script indented
on lambda(a, x)
set strIndent to leftSpace of a
{rows:strIndent & x & linefeed & rows of a, leftSpace:leftSpace of a & " "}
rows of foldr(indented, {rows:"", leftSpace:""}, map(spaced, lstTriangle))
end run
Line 326 ⟶ 332:
-- GENERIC LIBRARY FUNCTIONS
--
on
set
repeat with i from 1 to lng▼
end repeat
▲ set v to mf's lambda(v, item i of xs, i, xs)
end
-- map :: (a -> b) -> [a] -> [b]▼
on map(f, xs)▼
set lng to length of xs▼
set lst to {}▼
▲ repeat with i from 1 to lng
end repeat
return lst▼
end tell
end map▼
-- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
Line 350 ⟶ 368:
return lst
end zipWith
▲-- map :: (a -> b) -> [a] -> [b]
▲on map(f, xs)
▲ set mf to mReturn(f)
▲ set lng to length of xs
▲ set lst to {}
▲ set end of lst to mf's lambda(item i of xs, i, xs)
▲ end repeat
▲ return lst
▲end map
▲ set o to ""
▲ set n to (n div 2)
▲ set s to (s & s)
▲ end repeat
Line 406 ⟶ 400:
end if
end mReturn</lang>
{{Out}}
<pre>
1
1
1
1
</pre>
=={{header|AutoHotkey}}==
|