September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,21 +0,0 @@
with Ada.Containers.Ordered_Sets;
with Ada.Text_IO; use Ada.Text_IO;
procedure Unique_Set is
package Int_Sets is new Ada.Containers.Ordered_Sets(Integer);
use Int_Sets;
Nums : array (Natural range <>) of Integer := (1,2,3,4,5,5,6,7,1);
Unique : Set;
Set_Cur : Cursor;
Success : Boolean;
begin
for I in Nums'range loop
Unique.Insert(Nums(I), Set_Cur, Success);
end loop;
Set_Cur := Unique.First;
loop
Put_Line(Item => Integer'Image(Element(Set_Cur)));
exit when Set_Cur = Unique.Last;
Set_Cur := Next(Set_Cur);
end loop;
end Unique_Set;

View file

@ -1,2 +0,0 @@
1 2 3 1 2 3 4 1
1 2 3 4

View file

@ -1,3 +0,0 @@
w1 2 3 1 2 3 4 1
((w)=w)/w
1 2 3 4

View file

@ -1,22 +1,22 @@
-- CASE INSENSITIVE VERSION
-- CASE-INSENSITIVE UNIQUE ELEMENTS ------------------------------------------
-- nub :: [a] -> [a]
on nub(xs)
-- Eq :: a -> a -> Bool
script Eq
on lambda(x, y)
on |λ|(x, y)
ignoring case
x = y
end ignoring
end lambda
end |λ|
end script
nubBy(Eq, xs)
end nub
-- TEST
on run {}
-- TEST ----------------------------------------------------------------------
on run
{intercalate(space, ¬
nub(splitOn(space, "4 3 2 8 0 1 9 5 1 7 6 3 9 9 4 2 1 5 3 2"))), ¬
intercalate("", ¬
@ -26,9 +26,40 @@ on run {}
end run
---------------------------------------------------------------------------
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- GENERIC FUNCTIONS
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
tell mReturn(f)
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
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
end script
end if
end mReturn
-- nubBy :: (a -> a -> Bool) -> [a] -> [a]
on nubBy(fnEq, xxs)
@ -41,9 +72,9 @@ on nubBy(fnEq, xxs)
-- notEq :: a -> Bool
script notEq
on lambda(a)
not (p's lambda(a, x))
end lambda
on |λ|(a)
not (p's |λ|(a, x))
end |λ|
end script
{x} & nubBy(fnEq, filter(notEq, xs))
@ -52,33 +83,6 @@ on nubBy(fnEq, xxs)
end if
end nubBy
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
tell mReturn(f)
set lst to {}
set lng to length of xs
repeat with i from 1 to lng
set v to item i of xs
if lambda(v, i, xs) then set end of lst to v
end repeat
return lst
end tell
end filter
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property lambda : f
end script
end if
end mReturn
-- FOR THE TEST
-- splitOn :: Text -> Text -> [Text]
on splitOn(strDelim, strMain)
set {dlm, my text item delimiters} to {my text item delimiters, strDelim}
@ -86,11 +90,3 @@ on splitOn(strDelim, strMain)
set my text item delimiters to dlm
return lstParts
end splitOn
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate

View file

@ -0,0 +1,15 @@
local items = {1,2,3,4,1,2,3,4,0/0,nil,"bird","cat","dog","dog","bird",0/0}
function rmdup(t)
local r,dup,c,NaN = {},{},1,{}
for i=1,#t do
local e = t[i]
local k = e~=e and NaN or e
if k~=nil and not dup[k] then
c, r[c], dup[k]= c+1, e, true
end
end
return r
end
print(table.concat(rmdup(items),' '))

View file

@ -1 +1,6 @@
List.sort_uniq compare [1;2;3;2;3;4]
let uniq l =
let rec tail_uniq a l =
match l with
| [] -> a
| hd::tl -> tail_uniq (hd::a) (List.filter (fun x -> x != hd) tl) in
tail_uniq [] l

View file

@ -0,0 +1 @@
List.sort_uniq compare [1;2;3;2;3;4]

View file

@ -0,0 +1,8 @@
data = .array~of(1, 2, 3, "a", "b", "c", 2, 3, 4, "b", "c", "d")
uniqueData = .set~new~union(data)~makearray~sort
say "Unique elements are"
say
do item over uniqueData
say item
end

View file

@ -1,12 +1,12 @@
/*REXX program removes any duplicate elements (items) that are in a list. */
$= '2 3 5 7 11 13 17 19 cats 222 -100.2 +11 1.1 +7 7. 7 5 5 3 2 0 4.4 2'
/*REXX program removes any duplicate elements (items) that are in a list (using a hash).*/
$= '2 3 5 7 11 13 17 19 cats 222 -100.2 +11 1.1 +7 7. 7 5 5 3 2 0 4.4 2' /*item list.*/
say 'original list:' $
say right(words($),17,'') 'words in the original list.'; say
z=; @.= /*initialize the NEW list and index list*/
do j=1 for words($); y=word($,j) /*process the words (items) in the list.*/
if @.y=='' then z=z y; @.y=. /*Not duplicated? Add to Z list, @ array*/
end /*j*/
say 'modified list:' space(z)
say right(words(z),17,'') 'words in the modified list.'
/*stick a fork in it, we're all done. */
say right( words($), 17, '') 'words in the original list.'
z=; @.= /*initialize the NEW list & index list.*/
do j=1 for words($); y=word($,j) /*process the words (items) in the list*/
if @.y=='' then z=z y; @.y=. /*Not duplicated? Add to Z list,@ array*/
end /*j*/
say
say 'modified list:' space(z)
say right( words(z), 17, '') 'words in the modified list.'
/*stick a fork in it, we're all done. */

View file

@ -1,12 +1,12 @@
/*REXX program to remove duplicate elements (items) in a list. */
$= '2 3 5 7 11 13 17 19 cats 222 -100.2 +11 1.1 +7 7. 7 5 5 3 2 0 4.4 2'
/*REXX program removes any duplicate elements (items) that are in a list (using a list).*/
$= '2 3 5 7 11 13 17 19 cats 222 -100.2 +11 1.1 +7 7. 7 5 5 3 2 0 4.4 2' /*item list.*/
say 'original list:' $
say right(words($),13) ' words in the original list.'; say
do j=words($) by -1 to 1; y=word($,j) /*process words in the list, */
_=wordpos(y, $, j+1); if _\==0 then $=delword($, _, 1) /*del if dup.*/
end /*j*/
say 'modified list:' space($)
say right(words($),13) ' words in the modified list.'
/*stick a fork in it, we're done.*/
say right( words($), 17, '') 'words in the original list.'
#=words($) /*process all the words in the list. */
do j=# by -1 for #; y=word($, j) /*get right-to-Left. */
_=wordpos(y, $, j + 1); if _\==0 then $=delword($,_,1) /*Dup? Then delete it*/
end /*j*/
say
say 'modified list:' space($)
say right( words(z), 17, '') 'words in the modified list.'
/*stick a fork in it, we're all done. */

View file

@ -1,13 +1,12 @@
/*REXX program to remove duplicate elements (items) in a list. */
old= '2 3 5 7 11 13 17 19 cats 222 -100.2 +11 1.1 +7 7. 7 5 5 3 2 0 4.4 2'
say 'original list:' old
say right(words(old),13) ' words in the original list.'; say
new= /*start with a clean slate. */
do j=1 for words(old); _=word(old,j) /*process the words in old list. */
if wordpos(_,new)==0 then new=new _ /*Doesn't exist? Then add to list*/
end /*j*/
/*REXX program removes any duplicate elements (items) that are in a list (using 2 lists)*/
old = '2 3 5 7 11 13 17 19 cats 222 -100.2 +11 1.1 +7 7. 7 5 5 3 2 0 4.4 2'
say 'original list:' old
say right( words(old), 17, '') 'words in the original list.'
new= /*start with a clean (list) slate. */
do j=1 for words(old); _=word(old, j) /*process the words in the OLD list. */
if wordpos(_,new)==0 then new=new _ /*Doesn't exist? Then add word to NEW.*/
end /*j*/
say
say 'modified list:' space(new)
say right(words(new),13) ' words in the modified list.'
/*stick a fork in it, we're done.*/
say right( words(new), 17, '') 'words in the modified list.'
/*stick a fork in it, we're all done. */

View file

@ -0,0 +1,4 @@
proc unique(items);
seen := {};
return [item: item in items, nps in {#seen} | #(seen with:= item) > nps];
end proc;

View file

@ -0,0 +1,2 @@
items := [0,7,6,6,4,9,7,1,2,3,2];
print(unique(items));

View file

@ -0,0 +1,3 @@
proc unique(items);
return [item: item in {item: item in items}];
end proc;

View file

@ -0,0 +1,3 @@
set = new('set')
* Add all the elements of the array to the set.
add(set,array)

View file

@ -0,0 +1,25 @@
. clear all
. input x y
1 1
1 1
1 2
2 1
2 2
1 1
2 1
2 1
1 2
2 2
end
. duplicates drop x y, force
. list
+-------+
| x y |
|-------|
1. | 1 1 |
2. | 1 2 |
3. | 2 1 |
4. | 2 2 |
+-------+

View file

@ -0,0 +1,26 @@
. mata
: a=1,1\1,1\1,2\2,1\2,2\1,1\2,1\2,1\1,2\2,2
: a
1 2
+---------+
1 | 1 1 |
2 | 1 1 |
3 | 1 2 |
4 | 2 1 |
5 | 2 2 |
6 | 1 1 |
7 | 2 1 |
8 | 2 1 |
9 | 1 2 |
10 | 2 2 |
+---------+
: uniqrows(a)
1 2
+---------+
1 | 1 1 |
2 | 1 2 |
3 | 2 1 |
4 | 2 2 |
+---------+

View file

@ -0,0 +1,4 @@
zkl: Utils.Helpers.listUnique(T(1,3,2,9,1,2,3,8,8,"8",1,0,2,"8"))
L(1,3,2,9,8,"8",0)
zkl: "1,3,2,9,1,2,3,8,8,1,0,2".unique()
,012389

View file

@ -0,0 +1,2 @@
fcn listUnique(xs){
xs.reduce(fcn(us,s){us.holds(s) and us or us.append(s)},L()) }