函数式方法(haskell 编程语言):
-- function that having the two sublists with '0' and '1' ips,
-- filters and puts into the '1'
-- sublist all the '0' ips that are not included in '1'
fil [] result = result
fil (x: xs) result | (init x `elem` (map init result)) == False = fil xs (x:result)
| otherwise = fil xs result
-- function that filters '0' and '1' sublists
getsublist alist character = filter (\x-> (last x) == character) alist
> let a = ["192.168.0.168: 1", "192.168.0.158: 0", "192.168.0.198: 0", "192.168.0.148: 0", "192.168.0.158: 1", "192.168.0.168: 0"]
> let b = getsublist a '0'
> let c = getsublist a '1'
> fil b c
输出:
["192.168.0.148: 0","192.168.0.198: 0","192.168.0.168: 1","192.168.0.158: 1"]