Self-describing numbers: Difference between revisions
Content deleted Content added
→{{header|AppleScript}}: Updated predicate. |
|||
Line 128: | Line 128: | ||
on selfDescribes(x) |
on selfDescribes(x) |
||
set s to str(x) |
set s to str(x) |
||
set descripn to my str(|λ|(my groupBy(my eq, my sort(characters of s))) of my |
set descripn to my str(|λ|(my groupBy(my eq, my sort(characters of s))) of my ¬ |
||
described(characters of "0123456789")) |
|||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"})) |
|||
1 = (offset of descripn in s) and ¬ |
1 = (offset of descripn in s) and ¬ |
||
0 = ((items ((length of descripn) + 1) thru -1 of s) as string as integer) |
0 = ((items ((length of descripn) + 1) thru -1 of s) as string as integer) |
||
Line 165: | Line 165: | ||
unlines(map(test, ¬ |
unlines(map(test, ¬ |
||
{1210, 1211, 2020, 2022, 21200, 21203, 3211000, 3211004})) |
{1210, 1211, 2020, 2022, 21200, 21203, 3211000, 3211004})) |
||
end run |
end run |
||
Line 178: | Line 180: | ||
return true |
return true |
||
end |and| |
end |and| |
||
-- 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 |
|||
Line 184: | Line 200: | ||
a = b |
a = b |
||
end eq |
end eq |
||
-- filter :: (a -> Bool) -> [a] -> [a] |
|||
on filter(p, xs) |
|||
tell mReturn(p) |
|||
set lst to {} |
|||
set lng to length of xs |
|||
repeat with i from 1 to lng |
|||
set v to item i of xs |
|||
if |λ|(v, i, xs) then set end of lst to v |
|||
end repeat |
|||
return lst |
|||
end tell |
|||
end filter |
|||