Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
14
Task/Even-or-odd/AppleScript/even-or-odd-1.applescript
Normal file
14
Task/Even-or-odd/AppleScript/even-or-odd-1.applescript
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
set L to {3, 2, 1, 0, -1, -2, -3}
|
||||
|
||||
set evens to {}
|
||||
set odds to {}
|
||||
|
||||
repeat with x in L
|
||||
if (x mod 2 = 0) then
|
||||
set the end of evens to x's contents
|
||||
else
|
||||
set the end of odds to x's contents
|
||||
end if
|
||||
end repeat
|
||||
|
||||
return {even:evens, odd:odds}
|
||||
1
Task/Even-or-odd/AppleScript/even-or-odd-2.applescript
Normal file
1
Task/Even-or-odd/AppleScript/even-or-odd-2.applescript
Normal file
|
|
@ -0,0 +1 @@
|
|||
{even:{2, 0, -2}, odd:{3, 1, -1, -3}}
|
||||
67
Task/Even-or-odd/AppleScript/even-or-odd-3.applescript
Normal file
67
Task/Even-or-odd/AppleScript/even-or-odd-3.applescript
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
----------------------- EVEN OR ODD ------------------------
|
||||
|
||||
-- even :: Int -> Bool
|
||||
on even(n)
|
||||
0 = n mod 2
|
||||
end even
|
||||
|
||||
-- odd :: Int -> Bool
|
||||
on odd(n)
|
||||
not even(n)
|
||||
end odd
|
||||
|
||||
|
||||
--------------------------- TEST ---------------------------
|
||||
on run
|
||||
|
||||
partition(odd, enumFromTo(-6, 6))
|
||||
|
||||
--> {{-5, -3, -1, 1, 3, 5}, {-6, -4, -2, 0, 2, 4, 6}}
|
||||
end run
|
||||
|
||||
|
||||
-------------------- GENERICS FOR TEST ---------------------
|
||||
|
||||
-- enumFromTo :: Int -> Int -> [Int]
|
||||
on enumFromTo(m, n)
|
||||
if m ≤ n then
|
||||
set lst to {}
|
||||
repeat with i from m to n
|
||||
set end of lst to i
|
||||
end repeat
|
||||
lst
|
||||
else
|
||||
{}
|
||||
end if
|
||||
end enumFromTo
|
||||
|
||||
|
||||
|
||||
-- partition :: (a -> Bool) -> [a] -> ([a], [a])
|
||||
on partition(p, xs)
|
||||
tell mReturn(p)
|
||||
set {ys, zs} to {{}, {}}
|
||||
repeat with x in xs
|
||||
set v to contents of x
|
||||
if |λ|(v) then
|
||||
set end of ys to v
|
||||
else
|
||||
set end of zs to v
|
||||
end if
|
||||
end repeat
|
||||
end tell
|
||||
{ys, zs}
|
||||
end partition
|
||||
|
||||
|
||||
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
|
||||
on mReturn(f)
|
||||
-- 2nd class handler function lifted into 1st class script wrapper.
|
||||
if script is class of f then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
1
Task/Even-or-odd/AppleScript/even-or-odd-4.applescript
Normal file
1
Task/Even-or-odd/AppleScript/even-or-odd-4.applescript
Normal file
|
|
@ -0,0 +1 @@
|
|||
{{-5, -3, -1, 1, 3, 5}, {-6, -4, -2, 0, 2, 4, 6}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue