September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,8 +1,10 @@
|
|||
-- Int -> Int -> Int -> [[Int]]
|
||||
-- SPIRAL MATRIX -------------------------------------------------------------
|
||||
|
||||
-- spiral :: Int -> Int -> Int -> [[Int]]
|
||||
on spiral(lngRows, lngCols, nStart)
|
||||
if lngRows > 0 then
|
||||
{range(nStart, (nStart + lngCols) - 1)} & ¬
|
||||
map(my _reverse, ¬
|
||||
{enumFromTo(nStart, (nStart + lngCols) - 1)} & ¬
|
||||
map(my |reverse|, ¬
|
||||
transpose(spiral(lngCols, lngRows - 1, nStart + lngCols)))
|
||||
else
|
||||
{{}}
|
||||
|
|
@ -10,7 +12,7 @@ on spiral(lngRows, lngCols, nStart)
|
|||
end spiral
|
||||
|
||||
|
||||
-- TEST
|
||||
-- TEST ----------------------------------------------------------------------
|
||||
on run
|
||||
set n to 5
|
||||
set lstSpiral to spiral(n, n, 0)
|
||||
|
|
@ -24,17 +26,17 @@ on run
|
|||
end run
|
||||
|
||||
|
||||
-- WIKI TABLE FORMAT
|
||||
-- WIKI TABLE FORMAT ---------------------------------------------------------
|
||||
|
||||
-- wikiTable :: [Text] -> Bool -> Text -> Text
|
||||
on wikiTable(lstRows, blnHdr, strStyle)
|
||||
script fWikiRows
|
||||
on lambda(lstRow, iRow)
|
||||
on |λ|(lstRow, iRow)
|
||||
set strDelim to cond(blnHdr and (iRow = 0), "!", "|")
|
||||
set strDbl to strDelim & strDelim
|
||||
linefeed & "|-" & linefeed & strDelim & space & ¬
|
||||
intercalate(space & strDbl & space, lstRow)
|
||||
end lambda
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
linefeed & "{| class=\"wikitable\" " & ¬
|
||||
|
|
@ -44,57 +46,20 @@ on wikiTable(lstRows, blnHdr, strStyle)
|
|||
end wikiTable
|
||||
|
||||
|
||||
-- GENERIC LIBRARY FUNCTIONS
|
||||
-- GENERIC FUNCTIONS ---------------------------------------------------------
|
||||
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
tell mReturn(f)
|
||||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to lambda(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end map
|
||||
|
||||
-- transpose :: [[a]] -> [[a]]
|
||||
on transpose(xss)
|
||||
script column
|
||||
on lambda(_, iCol)
|
||||
script row
|
||||
on lambda(xs)
|
||||
item iCol of xs
|
||||
end lambda
|
||||
end script
|
||||
|
||||
map(row, xss)
|
||||
end lambda
|
||||
end script
|
||||
|
||||
map(column, item 1 of xss)
|
||||
end transpose
|
||||
|
||||
-- _reverse :: [a] -> [a]
|
||||
on _reverse(xs)
|
||||
if class of xs is text then
|
||||
(reverse of characters of xs) as text
|
||||
-- cond :: Bool -> a -> a -> a
|
||||
on cond(bool, x, y)
|
||||
if bool then
|
||||
x
|
||||
else
|
||||
reverse of xs
|
||||
y
|
||||
end if
|
||||
end _reverse
|
||||
end cond
|
||||
|
||||
-- Text -> [Text] -> Text
|
||||
on intercalate(strText, lstText)
|
||||
set {dlm, my text item delimiters} to {my text item delimiters, strText}
|
||||
set strJoined to lstText as text
|
||||
set my text item delimiters to dlm
|
||||
return strJoined
|
||||
end intercalate
|
||||
|
||||
-- range :: Int -> Int -> [Int]
|
||||
on range(m, n)
|
||||
if n < m then
|
||||
-- enumFromTo :: Int -> Int -> [Int]
|
||||
on enumFromTo(m, n)
|
||||
if m > n then
|
||||
set d to -1
|
||||
else
|
||||
set d to 1
|
||||
|
|
@ -104,16 +69,27 @@ on range(m, n)
|
|||
set end of lst to i
|
||||
end repeat
|
||||
return lst
|
||||
end range
|
||||
end enumFromTo
|
||||
|
||||
-- cond :: Bool -> (a -> b) -> (a -> b) -> (a -> b)
|
||||
on cond(bool, f, g)
|
||||
if bool then
|
||||
f
|
||||
else
|
||||
g
|
||||
end if
|
||||
end cond
|
||||
-- Text -> [Text] -> Text
|
||||
on intercalate(strText, lstText)
|
||||
set {dlm, my text item delimiters} to {my text item delimiters, strText}
|
||||
set strJoined to lstText as text
|
||||
set my text item delimiters to dlm
|
||||
return strJoined
|
||||
end intercalate
|
||||
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
tell mReturn(f)
|
||||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end map
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
|
|
@ -122,7 +98,33 @@ on mReturn(f)
|
|||
f
|
||||
else
|
||||
script
|
||||
property lambda : f
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
-- reverse :: [a] -> [a]
|
||||
on |reverse|(xs)
|
||||
if class of xs is text then
|
||||
(reverse of characters of xs) as text
|
||||
else
|
||||
reverse of xs
|
||||
end if
|
||||
end |reverse|
|
||||
|
||||
-- transpose :: [[a]] -> [[a]]
|
||||
on transpose(xss)
|
||||
script column
|
||||
on |λ|(_, iCol)
|
||||
script row
|
||||
on |λ|(xs)
|
||||
item iCol of xs
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
map(row, xss)
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
map(column, item 1 of xss)
|
||||
end transpose
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue