March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -0,0 +1,9 @@
b = [1, 5, 2, 6, 6, 2, 2, 1, 9, 8, 6, 5]
// One way, using OrderedList. An OrderedList is a type of array that keeps
// its elements in order. The items must be comparable.
a = new OrderedList
println[a.insertAllUnique[b]]
// Another way, using the "set" datatype and back to an array.
println[toArray[toSet[b]]

View file

@ -0,0 +1,7 @@
let uniq lst =
let unique_set = Hashtbl.create (List.length lst) in
List.iter (fun x -> Hashtbl.replace unique_set x ()) lst;
Hashtbl.fold (fun x () xs -> x :: xs) unique_set []
let _ =
uniq [1;2;3;2;3;4]

View file

@ -0,0 +1,8 @@
let uniq lst =
let seen = Hashtbl.create (List.length lst) in
List.filter (fun x -> let tmp = not (Hashtbl.mem seen x) in
Hashtbl.replace seen x ();
tmp) lst
let _ =
uniq [1;2;3;2;3;4]

View file

@ -1,7 +0,0 @@
let uniq lst =
let unique_set = Hashtbl.create (List.length lst) in
List.iter (fun x -> Hashtbl.replace unique_set x ()) lst;
Hashtbl.fold (fun x () xs -> x :: xs) unique_set []
let _ =
uniq [1;2;3;2;3;4]

View file

@ -1,7 +1 @@
sub nub (@a) {
my @b;
none(@b) eqv $_ and push @b, $_ for @a;
return @b;
}
my @unique = nub [1, 2, 3, 5, 2, 4, 3, -3, 7, 5, 6];
my @unique = [1, 2, 3, 5, 2, 4, 3, -3, 7, 5, 6].uniq;

View file

@ -1 +1 @@
my @unique = [1, 2, 3, 5, 2, 4, 3, -3, 7, 5, 6].uniq;
set(1,2,3,5,2,4,3,-3,7,5,6).list

View file

@ -0,0 +1 @@
call filter(list, 'count(list, v:val) == 1')