Jump to content

Common sorted list: Difference between revisions

(Added Wren)
Line 81:
import "/sort" for Sort
 
var distinctUnion2distinctSortedUnion = Fn.new { |l1, l2ll| Lst.distinct(l1 + l2) }
returnvar res = ll.skip(2).reduce(first2[]) { |acc, l| distinctUnion2.call(acc, + l) }
 
res = Lst.distinct(res)
var distinctUnionN = Fn.new { |ll|
Sort.insertion(ures)
var n = ll.count
if (n == 0) return llres
if (n == 1) return ll[0]
var first2 = distinctUnion2.call(ll[0], ll[1])
if (n == 2) return first2
return ll.skip(2).reduce(first2) { |acc, l| distinctUnion2.call(acc, l) }
}
 
var ll = [[5, 1, 3, 8, 9, 4, 8, 7], [3, 5, 9, 8, 4], [1, 3, 7, 9]]
System.print("Distinct sorted union of %(ll) is:")
System.print(udistinctSortedUnion.call(ll))</lang>
var u = distinctUnionN.call(ll)
Sort.insertion(u)
System.print(u)</lang>
 
{{out}}
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.