Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,48 @@
* Remove duplicate elements - 18/10/2015
REMDUP CSECT
USING REMDUP,R15 set base register
SR R6,R6 i=0
LA R8,1 k=1
LOOPK C R8,N do k=1 to n
BH ELOOPK
LR R1,R8 k
SLA R1,2
L R9,T-4(R1) e=t(k)
LR R7,R8 k
BCTR R7,0 j=k-1
LOOPJ C R7,=F'1' do j=k-1 to 1 by -1
BL ELOOPJ
LR R1,R7 j
SLA R1,2
L R2,T-4(R1) t(j)
CR R9,R2 if e=t(j) then goto iter
BE ITER
BCTR R7,0 j=j-1
B LOOPJ
ELOOPJ LA R6,1(R6) i=i+1
LR R1,R6 i
SLA R1,2
ST R9,T-4(R1) t(i)=e
ITER LA R8,1(R8) k=k+1
B LOOPK
ELOOPK LA R10,PG pgi=@pg
LA R8,1 k=1
LOOP CR R8,R6 do k=1 to i
BH ELOOP
LR R1,R8 k
SLA R1,2
L R2,T-4(R1) t(k)
XDECO R2,PG+80 edit t(k)
MVC 0(3,R10),PG+89 output t(k) on 3 char
LA R10,3(R10) pgi=pgi+3
LA R8,1(R8) k=k+1
B LOOP
ELOOP XPRNT PG,80 print buffer
XR R15,R15 set return code
BR R14 return to caller
T DC F'6',F'6',F'1',F'5',F'6',F'2',F'1',F'7',F'5',F'22'
DC F'4',F'19',F'1',F'1',F'6',F'8',F'9',F'10',F'11',F'12'
N DC A((N-T)/4) number of T items
PG DC CL92' '
YREGS
END REMDUP

View file

@ -0,0 +1,7 @@
void main()
{
import std.stdio, std.algorithm, std.array;
auto a = [5,4,32,7,6,4,2,6,0,8,6,9].sort.uniq.array;
a.writeln;
}

View file

@ -0,0 +1,28 @@
defmodule RC do
# hash table approach
def uniq1(list) do
Enum.reduce(list, HashSet.new, fn x, set -> Set.put(set, x) end)
|> Set.to_list
end
# Sort approach
def uniq2(list), do: Enum.sort(list) |> uniq2([])
defp uniq2([], uniq), do: Enum.reverse(uniq)
defp uniq2([h|t], uniq) when h==hd(uniq), do: uniq2(t, uniq)
defp uniq2([h|t], uniq) , do: uniq2(t, [h | uniq])
# Go through the list approach
def uniq3(list), do: uniq3(list, [])
defp uniq3([], uniq), do: Enum.reverse(uniq)
defp uniq3([h|t], uniq) do
if Enum.member?(uniq, h), do: uniq3(t, uniq), else: uniq3(t, [h | uniq])
end
end
list = [1,1,2,1,'redundant',[1,2,3],[1,2,3],'redundant']
IO.inspect Enum.uniq(list)
IO.inspect RC.uniq1(list)
IO.inspect RC.uniq2(list)
IO.inspect RC.uniq3(list)

View file

@ -0,0 +1,3 @@
print $ unique [4, 5, 4, 2, 3, 3, 4]
[4,5,2,3]

View file

@ -0,0 +1,4 @@
import qualified Data.Set as Set
unique :: Ord a => [a] -> [a]
unique = Set.toList . Set.fromList

View file

@ -0,0 +1,8 @@
import Data.Set
unique :: Ord a => [a] -> [a]
unique = loop empty
where
loop s [] = []
loop s (x : xs) | member x s = loop s xs
| otherwise = x : loop (insert x s) xs

View file

@ -0,0 +1,5 @@
import Data.List
unique :: Eq a => [a] -> [a]
unique [] = []
unique (x : xs) = x : unique (filter (x /=) xs)

View file

@ -0,0 +1,3 @@
import Data.List
Data.List.nub :: Eq a => [a] -> [a]
Data.List.Unique.unique :: Ord a => [a] -> [a]

View file

@ -1,2 +0,0 @@
values = [1,2,3,2,3,4]
unique = List.nub values

View file

@ -0,0 +1,3 @@
Array.prototype.unique = function() {
return this.sort().reduce( (a,e) => e === a[a.length-1] ? a : (a.push(e), a), [] )
}

View file

@ -0,0 +1,3 @@
Array.prototype.unique = function() {
return [... new Set(this)]
}

View file

@ -0,0 +1,15 @@
function uniq(lst) {
var u = [],
dct = {},
i = lst.length,
v;
while (i--) {
v = lst[i], dct[v] || (
dct[v] = u.push(v)
);
}
u.sort(); // optional
return u;
}

View file

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

View file

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

View file

@ -0,0 +1,3 @@
from collections import OrderedDict as od
print(list(od.fromkeys([1, 2, 3, 'a', 'b', 'c', 2, 3, 4, 'b', 'c', 'd']).keys()))

View file

@ -1,12 +1,12 @@
/*REXX program to remove duplicate elements (items) in a list. */
/*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'
say 'original list:' $
say right(words($),13) ' words in the original list.'; say
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*/
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 '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,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. */
$= '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:' $
say right(words($),13) ' words in the original list.'; say
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*/
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(new)
say right(words(new),13) ' words in the modified list.'
say 'modified list:' space($)
say right(words($),13) ' words in the modified list.'
/*stick a fork in it, we're done.*/

View file

@ -1,28 +1,13 @@
/* REXX ************************************************************
* 26.11.2012 Walter Pachl
* added: show multiple occurrences
**********************************************************************/
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 'old list='old
say 'words in the old list=' words(old)
new=''
found.=0
count.=0
Do While old<>''
Parse Var old w old
If found.w=0 Then Do
new=new w
found.w=1
End
count.w=count.w+1
End
say 'new list='strip(new)
say 'words in the new list=' words(new)
Say 'Multiple occurrences:'
Say 'occ word'
Do While new<>''
Parse Var new w new
If count.w>1 Then
Say right(count.w,3) w
End
/*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*/
say 'modified list:' space(new)
say right(words(new),13) ' words in the modified list.'
/*stick a fork in it, we're done.*/

View file

@ -0,0 +1,28 @@
/* REXX ************************************************************
* 26.11.2012 Walter Pachl
* added: show multiple occurrences
**********************************************************************/
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 'old list='old
say 'words in the old list=' words(old)
new=''
found.=0
count.=0
Do While old<>''
Parse Var old w old
If found.w=0 Then Do
new=new w
found.w=1
End
count.w=count.w+1
End
say 'new list='strip(new)
say 'words in the new list=' words(new)
Say 'Multiple occurrences:'
Say 'occ word'
Do While new<>''
Parse Var new w new
If count.w>1 Then
Say right(count.w,3) w
End

View file

@ -10,6 +10,5 @@ def unique(array)
return pure
end
unique ["hi","hey","hello","hi","hey","heyo"] # => ["hi", "hey", "hello", "heyo"]
unique [1,2,3,4,1,2,3,5,1,2,3,4,5] # => [1,2,3,4,5]

View file

@ -0,0 +1,15 @@
Function remove_duplicates(list)
arr = Split(list,",")
Set dict = CreateObject("Scripting.Dictionary")
For i = 0 To UBound(arr)
If dict.Exists(arr(i)) = False Then
dict.Add arr(i),""
End If
Next
For Each key In dict.Keys
tmp = tmp & key & ","
Next
remove_duplicates = Left(tmp,Len(tmp)-1)
End Function
WScript.Echo remove_duplicates("a,a,b,b,c,d,e,d,f,f,f,g,h")