Greatest subsequential sum: Difference between revisions

Content added Content deleted
m (→‎{{header|AppleScript}}: Updated primitives – max and gt)
Line 126: Line 126:
end tell
end tell
end foldl
end foldl

-- gt :: Ord a => a -> a -> Bool
on gt(x, y)
set c to class of x
if record is c or list is c then
fst(x) > fst(y)
else
x > y
end if
end gt


-- fst :: (a, b) -> a
-- fst :: (a, b) -> a
Line 150: Line 160:
-- max :: Ord a => a -> a -> a
-- max :: Ord a => a -> a -> a
on max(x, y)
on max(x, y)
set c to class of x
if gt(x, y) then
if list is c or record is c then
set {a, b} to {fst(x), fst(y)}
else
set {a, b} to {x, y}
end if
if a > b then
x
x
else
else