lambdaway
::
intersection
6
|
list
|
login
|
load
|
|
_h1 intersection _p Following [[http://rosettacode.org/wiki/Common_list_elements|http://rosettacode.org/wiki/Common_list_elements]] {prewrap '{intersection {A.new 3 5 6 2 9 8 4} {A.new 2 5 1 3 8 9 4 6} {A.new 1 3 7 6 9} } -> {intersection {A.new 3 5 6 2 9 8 4} {A.new 2 5 1 3 8 9 4 6} {A.new 1 3 7 6 9} } A isinB isinC [] 2 yes no [] 5 no no [] 1 no no [] 3 yes yes [3] 8 yes no [3] 9 yes yes [3,9] 4 yes no [3,9] 6 yes yes [3,9,6] '{def intersection {def intersection.r {lambda {:a :b :c :d} {if {A.empty? :a} then :d else {intersection.r {A.rest :a} :b :c {if {and {> {A.in? {A.first :a} :b} -1} {> {A.in? {A.first :a} :c} -1}} then {A.addlast! {A.first :a} :d} else :d} }}}} {lambda {:a :b :c} {A.sort! < {intersection.r :a :b :c {A.new}}} }} -> {def intersection {def intersection.r {lambda {:a :b :c :d} {if {A.empty? :a} then :d else {intersection.r {A.rest :a} :b :c {if {and {> {A.in? {A.first :a} :b} -1} {> {A.in? {A.first :a} :c} -1}} then {A.addlast! {A.first :a} :d} else :d} }}}} {lambda {:a :b :c} {A.sort! < {intersection.r :a :b :c {A.new}}} }} } _p Doesn't depend on input lists order, but better if it is in increasing length.
lambdaway v.20211111