June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,5 @@
|
|||
index x;
|
||||
|
||||
list(1, 2, 3, 1, 2, 3, 4, 1).ucall(i_add, 1, x, 0);
|
||||
x.i_vcall(o_, 1, " ");
|
||||
o_newline();
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
integer a;
|
||||
index x;
|
||||
list l;
|
||||
|
||||
l = list(8, 2, 1, 8, 2, 1, 4, 8);
|
||||
|
||||
for (, a in l) {
|
||||
if ((x[a] += 1) == 1) {
|
||||
o_(" ", a);
|
||||
}
|
||||
}
|
||||
o_newline();
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import extensions.
|
||||
import system'collections.
|
||||
import system'routines.
|
||||
|
||||
program =
|
||||
[
|
||||
var nums := (1,1,2,3,4,4).
|
||||
dictionary unique := Dictionary new.
|
||||
|
||||
nums forEach(:n)[ unique[n] := n ].
|
||||
|
||||
console printLine(unique).
|
||||
].
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
program remove_dups
|
||||
implicit none
|
||||
integer :: example(12) ! The input
|
||||
integer :: res(size(example)) ! The output
|
||||
integer :: k ! The number of unique elements
|
||||
integer :: i
|
||||
|
||||
example = [1, 2, 3, 2, 2, 4, 5, 5, 4, 6, 6, 5]
|
||||
k = 1
|
||||
res(1) = example(1)
|
||||
do i=2,size(example)
|
||||
! if the number already exist in res check next
|
||||
if (any( res == example(i) )) cycle
|
||||
! No match found so add it to the output
|
||||
k = k + 1
|
||||
res(k) = example(i)
|
||||
end do
|
||||
|
||||
write(*,advance='no',fmt='(a,i0,a)') 'Unique list has ',k,' elements: '
|
||||
write(*,*) res(1:k)
|
||||
end program remove_dups
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
10 ' Remove Duplicates
|
||||
20 OPTION BASE 1
|
||||
30 LET MAXI% = 7
|
||||
40 DIM D(7), R(7): ' data, result
|
||||
50 ' Set the data.
|
||||
60 FOR I% = 1 TO 7
|
||||
70 READ D(I%)
|
||||
80 NEXT I%
|
||||
90 ' Remove duplicates.
|
||||
100 LET R(1) = D(1)
|
||||
110 LET LRI% = 1: ' last index of result
|
||||
120 LET P% = 1: ' position
|
||||
130 WHILE P% < MAXI%
|
||||
140 LET P% = P% + 1
|
||||
150 LET ISNEW = 1: ' is a new number?
|
||||
160 LET RI% = 1: ' current index of result
|
||||
170 WHILE (RI% <= LRI%) AND ISNEW
|
||||
180 IF D(P%) = R(RI%) THEN LET ISNEW = 0
|
||||
190 LET RI% = RI% + 1
|
||||
200 WEND
|
||||
210 IF ISNEW THEN LET LRI% = LRI% + 1: LET R(LRI%) = D(P%)
|
||||
220 WEND
|
||||
230 FOR RI% = 1 TO LRI%
|
||||
240 PRINT R(RI%)
|
||||
250 NEXT RI%
|
||||
260 END
|
||||
1000 DATA 1, 2, 2, 3, 4, 5, 5
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
Public Sub Main()
|
||||
Dim sString As String[] = Split("Now is the time for all the good men to come to the aid of the good party 1 2 1 3 3 3 2 1 1 2 3 4 33 2 5 4 333 5", " ")
|
||||
Dim sFix As New String[]
|
||||
Dim sTemp As String
|
||||
|
||||
For Each sTemp In sString
|
||||
sTemp &= " "
|
||||
If InStr(sFix.Join(" ") & " ", sTemp) Then Continue
|
||||
sFix.Add(Trim(sTemp))
|
||||
Next
|
||||
|
||||
Print sFix.Join(" ")
|
||||
|
||||
End
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
a = [1,2,3,4,1,2,3,4]
|
||||
unique(a)
|
||||
a = [1, 2, 3, 4, 1, 2, 3, 4]
|
||||
@show unique(a) Set(a)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
MODULE RemoveDuplicates;
|
||||
|
||||
FROM STextIO IMPORT
|
||||
WriteLn;
|
||||
FROM SWholeIO IMPORT
|
||||
WriteInt;
|
||||
|
||||
TYPE
|
||||
TArrayRange = [1 .. 7];
|
||||
TArray = ARRAY TArrayRange OF INTEGER;
|
||||
|
||||
VAR
|
||||
DataArray, ResultArray: TArray;
|
||||
ResultIndex, LastResultIndex, Position: CARDINAL;
|
||||
IsNewNumber: BOOLEAN;
|
||||
|
||||
BEGIN
|
||||
(* Set the data. *);
|
||||
DataArray[1] := 1;
|
||||
DataArray[2] := 2;
|
||||
DataArray[3] := 2;
|
||||
DataArray[4] := 3;
|
||||
DataArray[5] := 4;
|
||||
DataArray[6] := 5;
|
||||
DataArray[7] := 5;
|
||||
|
||||
ResultArray[1] := DataArray[1];
|
||||
LastResultIndex := 1;
|
||||
Position := 1;
|
||||
WHILE Position < HIGH(DataArray) DO
|
||||
INC(Position);
|
||||
IsNewNumber := TRUE;
|
||||
ResultIndex := 1;
|
||||
WHILE (ResultIndex <= LastResultIndex) AND IsNewNumber DO
|
||||
IF DataArray[Position] = ResultArray[ResultIndex] THEN
|
||||
IsNewNumber := FALSE;
|
||||
END;
|
||||
INC(ResultIndex);
|
||||
END;
|
||||
IF IsNewNumber THEN
|
||||
INC(LastResultIndex);
|
||||
ResultArray[LastResultIndex] := DataArray[Position];
|
||||
END
|
||||
END;
|
||||
FOR ResultIndex := 1 TO LastResultIndex DO
|
||||
WriteInt(ResultArray[ResultIndex], 1);
|
||||
WriteLn;
|
||||
END;
|
||||
END RemoveDuplicates.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
>> items: [1 "a" "c" 1 3 4 5 "c" 3 4 5]
|
||||
>> unique items
|
||||
== [1 "a" "c" 3 4 5]
|
||||
|
|
@ -1,16 +1,19 @@
|
|||
use std::vec::Vec;
|
||||
use std::collections::HashSet;
|
||||
use std::hash::Hash;
|
||||
use std::cmp::Eq;
|
||||
|
||||
fn main(){
|
||||
let mut sample_elements = vec![0u8,0,1,1,2,3,2];
|
||||
println!("Before removal of duplicates : {:?}", sample_elements);
|
||||
remove_duplicate_elements(&mut sample_elements);
|
||||
println!("After removal of duplicates : {:?}", sample_elements);
|
||||
}
|
||||
|
||||
fn remove_duplicate_elements<T : Hash + Eq>(elements: &mut Vec<T>){
|
||||
let set : HashSet<_> = elements.drain(..).collect();
|
||||
fn remove_duplicate_elements_hashing<T: Hash + Eq>(elements: &mut Vec<T>) {
|
||||
let set: HashSet<_> = elements.drain(..).collect();
|
||||
elements.extend(set.into_iter());
|
||||
}
|
||||
|
||||
fn remove_duplicate_elements_sorting<T: Ord>(elements: &mut Vec<T>) {
|
||||
elements.sort_unstable(); // order does not matter
|
||||
elements.dedup();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut sample_elements = vec![0, 0, 1, 1, 2, 3, 2];
|
||||
println!("Before removal of duplicates : {:?}", sample_elements);
|
||||
remove_duplicate_elements_sorting(&mut sample_elements);
|
||||
println!("After removal of duplicates : {:?}", sample_elements);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
Option Explicit
|
||||
|
||||
Sub Main()
|
||||
Dim myArr() As Variant, i As Long
|
||||
|
||||
myArr = Remove_Duplicate(Array(1.23456789101112E+16, True, False, True, "Alpha", 1, 235, 4, 1.25, 1.25, "Beta", 1.23456789101112E+16, "Delta", "Alpha", "Charlie", 1, 2, "Foxtrot", "Foxtrot", "Alpha", 235))
|
||||
'return :
|
||||
For i = LBound(myArr) To UBound(myArr)
|
||||
Debug.Print myArr(i)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Function Remove_Duplicate(Arr As Variant) As Variant()
|
||||
Dim myColl As New Collection, Temp() As Variant, i As Long, cpt As Long
|
||||
|
||||
ReDim Temp(UBound(Arr))
|
||||
For i = LBound(Arr) To UBound(Arr)
|
||||
On Error Resume Next
|
||||
myColl.Add CStr(Arr(i)), CStr(Arr(i))
|
||||
If Err.Number > 0 Then
|
||||
On Error GoTo 0
|
||||
Else
|
||||
Temp(cpt) = Arr(i)
|
||||
cpt = cpt + 1
|
||||
End If
|
||||
Next i
|
||||
ReDim Preserve Temp(cpt - 1)
|
||||
Remove_Duplicate = Temp
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue