September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
8
Task/Even-or-odd/AppleScript/even-or-odd-1.applescript
Normal file
8
Task/Even-or-odd/AppleScript/even-or-odd-1.applescript
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
set nList to {3, 2, 1, 0, -1, -2, -3}
|
||||
repeat with n in nList
|
||||
if (n / 2) = n / 2 as integer then
|
||||
log "Value " & n & " is even."
|
||||
else
|
||||
log "Value " & n & " is odd."
|
||||
end if
|
||||
end repeat
|
||||
45
Task/Even-or-odd/AppleScript/even-or-odd-2.applescript
Normal file
45
Task/Even-or-odd/AppleScript/even-or-odd-2.applescript
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
-- even :: Integral a => a -> Bool
|
||||
on even(n)
|
||||
n mod 2 = 0
|
||||
end even
|
||||
|
||||
-- odd :: Integral a => a -> Bool
|
||||
on odd(n)
|
||||
not even(n)
|
||||
end odd
|
||||
|
||||
|
||||
-- GENERIC FUNCTIONS FOR TEST ----------------------------------
|
||||
|
||||
-- filter :: (a -> Bool) -> [a] -> [a]
|
||||
on filter(f, xs)
|
||||
tell mReturn(f)
|
||||
set lst to {}
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to item i of xs
|
||||
if lambda(v, i, xs) then set end of lst to v
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end filter
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property lambda : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
|
||||
-- TEST ---------------------------------------------------------
|
||||
on run
|
||||
set xs to [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
|
||||
|
||||
{filter(even, xs), filter(odd, xs)}
|
||||
end run
|
||||
1
Task/Even-or-odd/AppleScript/even-or-odd-3.applescript
Normal file
1
Task/Even-or-odd/AppleScript/even-or-odd-3.applescript
Normal file
|
|
@ -0,0 +1 @@
|
|||
{{-6, -4, -2, 0, 2, 4, 6}, {-5, -3, -1, 1, 3, 5}}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
set nList to {3, 2, 1, 0, -1, -2, -3}
|
||||
repeat with n in nList
|
||||
if (n / 2) = n / 2 as integer then
|
||||
log "Value " & n & " is even."
|
||||
else
|
||||
log "Value " & n & " is odd."
|
||||
end if
|
||||
end repeat
|
||||
Loading…
Add table
Add a link
Reference in a new issue