Munchausen numbers: Difference between revisions

Content added Content deleted
(→‎{{header|AppleScript}}: Added subheadings after restoring inadvertent deletion of another variant.)
Line 252: Line 252:
=={{header|AppleScript}}==
=={{header|AppleScript}}==
===Functional===
===Functional===
<lang AppleScript>-- MUNCHAUSEN NUMBER ? -------------------------------------------------------
<lang AppleScript>------------------- MUNCHAUSEN NUMBER ? --------------------


-- isMunchausen :: Int -> Bool
-- isMunchausen :: Int -> Bool
Line 266: Line 266:
(class of n is integer) and ¬
(class of n is integer) and ¬
foldl(digitPowerSum, 0, characters of (n as string)) = n
n = foldl(digitPowerSum, 0, characters of (n as string))
end isMunchausen
end isMunchausen




-- TEST ----------------------------------------------------------------------
--------------------------- TEST ---------------------------
on run
on run
Line 281: Line 281:




-- GENERIC FUNCTIONS ---------------------------------------------------------
-------------------- GENERIC FUNCTIONS ---------------------


-- enumFromTo :: Int -> Int -> [Int]
-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
on enumFromTo(m, n)
if m > n then
if m n then
set d to -1
set lst to {}
repeat with i from m to n
set end of lst to i
end repeat
lst
else
else
set d to 1
{}
end if
end if
set lst to {}
repeat with i from m to n by d
set end of lst to i
end repeat
return lst
end enumFromTo
end enumFromTo


-- filter :: (a -> Bool) -> [a] -> [a]
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
on filter(p, xs)
tell mReturn(f)
tell mReturn(p)
set lst to {}
set lst to {}
set lng to length of xs
set lng to length of xs