langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
3
Task/Filter/Nemerle/filter-1.nemerle
Normal file
3
Task/Filter/Nemerle/filter-1.nemerle
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def original = $[1 .. 100];
|
||||
def filtered = original.Filter(fun(n) {n % 2 == 0});
|
||||
WriteLine($"$filtered");
|
||||
5
Task/Filter/Nemerle/filter-2.nemerle
Normal file
5
Task/Filter/Nemerle/filter-2.nemerle
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Filter[T] (a : array[T], f : T -> bool) : array[T]
|
||||
{
|
||||
def b = $[x | x in a, (f(x))];
|
||||
b.ToArray()
|
||||
}
|
||||
2
Task/Filter/NewLISP/filter.newlisp
Normal file
2
Task/Filter/NewLISP/filter.newlisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> (filter (fn (x) (= (% x 2) 0)) '(1 2 3 4 5 6 7 8 9 10))
|
||||
(2 4 6 8 10)
|
||||
2
Task/Filter/Nial/filter.nial
Normal file
2
Task/Filter/Nial/filter.nial
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
filter (= [0 first, mod [first, 2 first] ] ) 0 1 2 3 4 5 6 7 8 9 10
|
||||
=0 2 4 6 8 10
|
||||
2
Task/Filter/OCaml/filter.ocaml
Normal file
2
Task/Filter/OCaml/filter.ocaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
let lst = [1;2;3;4;5;6]
|
||||
let even_lst = List.filter (fun x -> x mod 2 = 0) lst
|
||||
19
Task/Filter/Objeck/filter.objeck
Normal file
19
Task/Filter/Objeck/filter.objeck
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use Structure;
|
||||
|
||||
bundle Default {
|
||||
class Evens {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
values := IntVector->New([1, 2, 3, 4, 5]);
|
||||
f := Filter(Int) ~ Bool;
|
||||
evens := values->Filter(f);
|
||||
|
||||
each(i : evens) {
|
||||
evens->Get(i)->PrintLine();
|
||||
};
|
||||
}
|
||||
|
||||
function : Filter(v : Int) ~ Bool {
|
||||
return v % 2 = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Task/Filter/Objective-C/filter-1.m
Normal file
7
Task/Filter/Objective-C/filter-1.m
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
NSArray *numbers = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],
|
||||
[NSNumber numberWithInt:2],
|
||||
[NSNumber numberWithInt:3],
|
||||
[NSNumber numberWithInt:4],
|
||||
[NSNumber numberWithInt:5], nil];
|
||||
NSArray *evens = [numbers objectsAtIndexes:[numbers indexesOfObjectsPassingTest:
|
||||
^BOOL(id obj, NSUInteger idx, BOOL *stop) { return [obj intValue] % 2 == 0; } ]];
|
||||
7
Task/Filter/Objective-C/filter-2.m
Normal file
7
Task/Filter/Objective-C/filter-2.m
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
NSArray *numbers = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],
|
||||
[NSNumber numberWithInt:2],
|
||||
[NSNumber numberWithInt:3],
|
||||
[NSNumber numberWithInt:4],
|
||||
[NSNumber numberWithInt:5], nil];
|
||||
NSPredicate *isEven = [NSPredicate predicateWithFormat:@"modulus:by:(SELF, 2) == 0"];
|
||||
NSArray *evens = [numbers filteredArrayUsingPredicate:isEven];
|
||||
32
Task/Filter/Objective-C/filter-3.m
Normal file
32
Task/Filter/Objective-C/filter-3.m
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSNumber ( ExtFunc )
|
||||
-(int) modulo2;
|
||||
@end
|
||||
|
||||
@implementation NSNumber ( ExtFunc )
|
||||
-(int) modulo2
|
||||
{
|
||||
return [self intValue] % 2;
|
||||
}
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSArray *numbers = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],
|
||||
[NSNumber numberWithInt:2],
|
||||
[NSNumber numberWithInt:3],
|
||||
[NSNumber numberWithInt:4],
|
||||
[NSNumber numberWithInt:5], nil];
|
||||
|
||||
NSPredicate *isEven = [NSPredicate predicateWithFormat:@"modulo2 == 0"];
|
||||
NSArray *evens = [numbers filteredArrayUsingPredicate:isEven];
|
||||
|
||||
NSLog(@"%@", evens);
|
||||
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
3
Task/Filter/Octave/filter.octave
Normal file
3
Task/Filter/Octave/filter.octave
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
arr = [1:100];
|
||||
evennums = arr( mod(arr, 2) == 0 );
|
||||
disp(evennums);
|
||||
3
Task/Filter/Oz/filter.oz
Normal file
3
Task/Filter/Oz/filter.oz
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
declare
|
||||
Lst = [1 2 3 4 5]
|
||||
LstEven = {Filter Lst IsEven}
|
||||
1
Task/Filter/PARI-GP/filter.pari
Normal file
1
Task/Filter/PARI-GP/filter.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
selecteven(v)=vecextract(v,1<<(#v\2*2+1)\3);
|
||||
9
Task/Filter/Pascal/filter.pascal
Normal file
9
Task/Filter/Pascal/filter.pascal
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
const
|
||||
|
||||
numbers:array[0..9] of integer = (0,1,2,3,4,5,6,7,8,9);
|
||||
|
||||
for x = 1 to 10 do
|
||||
if odd(numbers[x]) then
|
||||
writeln( 'The number ',numbers[x],' is odd.');
|
||||
else
|
||||
writeln( 'The number ',numbers[x],' is even.');
|
||||
2
Task/Filter/Perl-6/filter-1.pl6
Normal file
2
Task/Filter/Perl-6/filter-1.pl6
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
my @a = 1, 2, 3, 4, 5, 6;
|
||||
my @even = grep * %% 2, @a;
|
||||
1
Task/Filter/Perl-6/filter-2.pl6
Normal file
1
Task/Filter/Perl-6/filter-2.pl6
Normal file
|
|
@ -0,0 +1 @@
|
|||
my @even = @a.grep(* %% 2);
|
||||
1
Task/Filter/Perl-6/filter-3.pl6
Normal file
1
Task/Filter/Perl-6/filter-3.pl6
Normal file
|
|
@ -0,0 +1 @@
|
|||
@a .= grep(* %% 2);
|
||||
15
Task/Filter/Pop11/filter.pop11
Normal file
15
Task/Filter/Pop11/filter.pop11
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
;;; Generic filtering procedure which selects from ar elements
|
||||
;;; satisfying pred
|
||||
define filter_array(ar, pred);
|
||||
lvars i, k;
|
||||
stacklength() -> k;
|
||||
for i from 1 to length(ar) do
|
||||
;;; if element satisfies pred we leave it on the stack
|
||||
if pred(ar(i)) then ar(i) endif;
|
||||
endfor;
|
||||
;;; Collect elements from the stack into a vector
|
||||
return (consvector(stacklength() - k));
|
||||
enddefine;
|
||||
;;; Use it
|
||||
filter_array({1, 2, 3, 4, 5},
|
||||
procedure(x); not(testbit(x, 0)); endprocedure) =>
|
||||
1
Task/Filter/PostScript/filter.ps
Normal file
1
Task/Filter/PostScript/filter.ps
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1 2 3 4 5 6 7 8 9 10] {2 mod 0 eq} find
|
||||
2
Task/Filter/PowerShell/filter.psh
Normal file
2
Task/Filter/PowerShell/filter.psh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$array = -15..37
|
||||
$array | Where-Object { $_ % 2 -eq 0 }
|
||||
8
Task/Filter/Protium/filter.protium
Normal file
8
Task/Filter/Protium/filter.protium
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<@ LETCNWLSTLIT>numbers|1 2 3 4 5 6 7 8 9 10 11 12</@>
|
||||
<@ DEFLST>evens</@>
|
||||
<@ ENULSTLIT>numbers|
|
||||
<@ TSTEVEELTLST>...</@>
|
||||
<@ IFF>
|
||||
<@ LETLSTELTLST>evens|...</@>
|
||||
</@>
|
||||
</@>
|
||||
27
Task/Filter/PureBasic/filter.purebasic
Normal file
27
Task/Filter/PureBasic/filter.purebasic
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
Dim Tal.i(9)
|
||||
Dim Evens.i(0)
|
||||
|
||||
;- Set up an array with random numbers
|
||||
For i=0 To ArraySize(Tal())
|
||||
Tal(i)=Random(100)
|
||||
Next
|
||||
|
||||
;- Pick out all Even and save them
|
||||
j=0
|
||||
For i=0 To ArraySize(Tal())
|
||||
If Tal(i)%2=0
|
||||
ReDim Evens(j) ; extend the Array as we find new Even's
|
||||
Evens(j)=tal(i)
|
||||
j+1
|
||||
EndIf
|
||||
Next
|
||||
|
||||
;- Display the result
|
||||
PrintN("List of Randoms")
|
||||
For i=0 To ArraySize(Tal())
|
||||
Print(Str(Tal(i))+" ")
|
||||
Next
|
||||
PrintN(#CRLF$+#CRLF$+"List of Even(s)")
|
||||
For i=0 To ArraySize(Evens())
|
||||
Print(Str(Evens(i))+" ")
|
||||
Next
|
||||
5
Task/Filter/REBOL/filter.rebol
Normal file
5
Task/Filter/REBOL/filter.rebol
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a: [] repeat i 100 [append a i] ; Build and load array.
|
||||
|
||||
evens: [] repeat element a [if even? element [append evens element]]
|
||||
|
||||
print mold evens
|
||||
4
Task/Filter/Raven/filter.raven
Normal file
4
Task/Filter/Raven/filter.raven
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[ 0 1 2 3 4 5 6 7 8 9 ] as nums
|
||||
group nums each
|
||||
dup 1 & if drop
|
||||
list as evens
|
||||
19
Task/Filter/Run-BASIC/filter.run
Normal file
19
Task/Filter/Run-BASIC/filter.run
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
dim a1(100)
|
||||
count = 100
|
||||
for i = 1 to 100
|
||||
a1(i) = int(rnd(0)*100)+1
|
||||
count = count - (a1(i) mod 2)
|
||||
next
|
||||
|
||||
'dim the extract and fill it
|
||||
dim a2(count)
|
||||
for i = 1 to 100
|
||||
if not(a1(i) mod 2) then
|
||||
n = n+1
|
||||
a2(n) = a1(i)
|
||||
end if
|
||||
next
|
||||
|
||||
for i = 1 to count
|
||||
print a2(i)
|
||||
next
|
||||
14
Task/Filter/SQL/filter-1.sql
Normal file
14
Task/Filter/SQL/filter-1.sql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
--Create the original array (table #nos) with numbers from 1 to 10
|
||||
create table #nos (v int)
|
||||
declare @n int set @n=1
|
||||
while @n<=10 begin insert into #nos values (@n) set @n=@n+1 end
|
||||
|
||||
--Select the subset that are even into the new array (table #evens)
|
||||
select v into #evens from #nos where v % 2 = 0
|
||||
|
||||
-- Show #evens
|
||||
select * from #evens
|
||||
|
||||
-- Clean up so you can edit and repeat:
|
||||
drop table #nos
|
||||
drop table #evens
|
||||
7
Task/Filter/SQL/filter-2.sql
Normal file
7
Task/Filter/SQL/filter-2.sql
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
create temporary table nos (v int);
|
||||
insert into nos values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
|
||||
create temporary table evens (v int);
|
||||
insert into evens select v from nos where v%2=0;
|
||||
select * from evens order by v; /*2,4,6,8,10*/
|
||||
drop table nos;
|
||||
drop table evens;
|
||||
1
Task/Filter/SQL/filter-3.sql
Normal file
1
Task/Filter/SQL/filter-3.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
create temporary table evens select * from nos where v%2=0;
|
||||
2
Task/Filter/Salmon/filter-1.salmon
Normal file
2
Task/Filter/Salmon/filter-1.salmon
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
iterate(x; comprehend(y; [1...10]; y % 2 == 0) (y))
|
||||
x!;
|
||||
15
Task/Filter/Salmon/filter-2.salmon
Normal file
15
Task/Filter/Salmon/filter-2.salmon
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
variable my_array := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
variable write_position := 0;
|
||||
iterate (read_position; [0...9])
|
||||
{
|
||||
immutable elem := my_array[read_position];
|
||||
if (elem % 2 == 0)
|
||||
{
|
||||
my_array[write_position] := elem;
|
||||
++write_position;
|
||||
};
|
||||
};
|
||||
// Chop off the end of the array.
|
||||
my_array := my_array[0...write_position - 1];
|
||||
iterate(x; my_array)
|
||||
x!;
|
||||
9
Task/Filter/Seed7/filter.seed7
Normal file
9
Task/Filter/Seed7/filter.seed7
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
var array integer: arr is [] (1, 2, 3, 4, 5);
|
||||
var array integer: evens is 0 times 0;
|
||||
var integer: number is 0;
|
||||
|
||||
for number range arr do
|
||||
if not odd(number) then
|
||||
evens &:= [] (number);
|
||||
end if;
|
||||
end for;
|
||||
1
Task/Filter/Slate/filter.slate
Normal file
1
Task/Filter/Slate/filter.slate
Normal file
|
|
@ -0,0 +1 @@
|
|||
#(1 2 3 4 5) select: [| :number | number isEven].
|
||||
2
Task/Filter/Standard-ML/filter.ml
Normal file
2
Task/Filter/Standard-ML/filter.ml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
val ary = [1,2,3,4,5,6];
|
||||
List.filter (fn x => x mod 2 = 0) ary
|
||||
7
Task/Filter/TUSCRIPT/filter.tuscript
Normal file
7
Task/Filter/TUSCRIPT/filter.tuscript
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
$$ MODE TUSCRIPT
|
||||
arr="1'4'9'16'25'36'49'64'81'100",even=""
|
||||
LOOP nr=arr
|
||||
rest=MOD (nr,2)
|
||||
IF (rest==0) even=APPEND (even,nr)
|
||||
ENDLOOP
|
||||
PRINT even
|
||||
13
Task/Filter/Toka/filter.toka
Normal file
13
Task/Filter/Toka/filter.toka
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
10 cells is-array table
|
||||
10 cells is-array even
|
||||
{
|
||||
variable source
|
||||
[ swap source ! >r reset r> 0
|
||||
[ i source @ array.get
|
||||
dup 2 mod 0 <> [ drop ] ifTrue
|
||||
] countedLoop
|
||||
depth 0 swap [ i even array.put ] countedLoop
|
||||
]
|
||||
} is copy-even
|
||||
10 0 [ i i table array.put ] countedLoop
|
||||
table 10 copy-even
|
||||
8
Task/Filter/UNIX-Shell/filter.sh
Normal file
8
Task/Filter/UNIX-Shell/filter.sh
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
a=(1 2 3 4 5)
|
||||
unset e[@]
|
||||
for ((i=0;i<${#a[@]};i++)); do
|
||||
[ $((a[$i]%2)) -eq 0 ] && e[$i]="${a[$i]}"
|
||||
done
|
||||
|
||||
echo "${a[@]}"
|
||||
echo "${e[@]}"
|
||||
1
Task/Filter/UnixPipes/filter.unixpipes
Normal file
1
Task/Filter/UnixPipes/filter.unixpipes
Normal file
|
|
@ -0,0 +1 @@
|
|||
yes \ | cat -n | while read a; do ; expr $a % 2 >/dev/null && echo $a ; done
|
||||
8
Task/Filter/Ursala/filter-1.ursala
Normal file
8
Task/Filter/Ursala/filter-1.ursala
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#import std
|
||||
#import nat
|
||||
|
||||
x = <89,36,13,15,41,39,21,3,15,92,16,59,52,88,33,65,54,88,93,43>
|
||||
|
||||
#cast %nL
|
||||
|
||||
y = (not remainder\2)*~ x
|
||||
1
Task/Filter/Ursala/filter-2.ursala
Normal file
1
Task/Filter/Ursala/filter-2.ursala
Normal file
|
|
@ -0,0 +1 @@
|
|||
z = (not remainder)~| (36,<1,2,3,4,5,6,7,8,9,10,11,12>)
|
||||
1
Task/Filter/Ursala/filter-3.ursala
Normal file
1
Task/Filter/Ursala/filter-3.ursala
Normal file
|
|
@ -0,0 +1 @@
|
|||
shortcut = ~&ihBF x
|
||||
4
Task/Filter/V/filter.v
Normal file
4
Task/Filter/V/filter.v
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[even? dup 2 / >int 2 * - zero?].
|
||||
|
||||
[1 2 3 4 5 6 7 8 9] [even?] filter
|
||||
=[2 4 6 8]
|
||||
1
Task/Filter/Wrapl/filter-1.wrapl
Normal file
1
Task/Filter/Wrapl/filter-1.wrapl
Normal file
|
|
@ -0,0 +1 @@
|
|||
VAR a <- ALL 1:to(10);
|
||||
1
Task/Filter/Wrapl/filter-2.wrapl
Normal file
1
Task/Filter/Wrapl/filter-2.wrapl
Normal file
|
|
@ -0,0 +1 @@
|
|||
VAR e <- ALL a:values \ $ % 2 = 0;
|
||||
28
Task/Filter/XPL0/filter.xpl0
Normal file
28
Task/Filter/XPL0/filter.xpl0
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
include c:\cxpl\codes; \intrinsic 'code' declarations
|
||||
|
||||
proc Filter(A, B, Option); \Select all even numbers from array A
|
||||
int A, B, Option; \ and return them in B, unless Option = true
|
||||
int I, J;
|
||||
[J:= 0;
|
||||
for I:= 1 to A(0) do
|
||||
if (A(I)&1) = 0 then
|
||||
[J:= J+1;
|
||||
if Option then
|
||||
A(J):= A(I)
|
||||
else B(J):= A(I);
|
||||
];
|
||||
if Option then A(0):= J else B(0):= J;
|
||||
];
|
||||
|
||||
int Array, Evens(11), I;
|
||||
[Array:= [10, 3, 1, 4, 1, 5, 9, 2, 6, 5, 4];
|
||||
Filter(Array, Evens, false);
|
||||
for I:= 1 to Evens(0) do
|
||||
[IntOut(0, Evens(I)); ChOut(0, ^ )];
|
||||
CrLf(0);
|
||||
|
||||
Filter(Array, Evens \not used\, true);
|
||||
for I:= 1 to Array(0) do
|
||||
[IntOut(0, Array(I)); ChOut(0, ^ )];
|
||||
CrLf(0);
|
||||
]
|
||||
17
Task/Filter/XQuery/filter-1.xquery
Normal file
17
Task/Filter/XQuery/filter-1.xquery
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(: Sequence of numbers from 1 to 10 :)
|
||||
let $array := (1 to 10)
|
||||
|
||||
(: Short version :)
|
||||
let $short := $array[. mod 2 = 0]
|
||||
|
||||
(: Long version with a FLWOR expression :)
|
||||
let $long := for $value in $array
|
||||
where $value mod 2 = 0
|
||||
return $value
|
||||
|
||||
(: Show the results :)
|
||||
return
|
||||
<result>
|
||||
<short>{$short}</short>
|
||||
<long>{$short}</long>
|
||||
</result>
|
||||
5
Task/Filter/XQuery/filter-2.xquery
Normal file
5
Task/Filter/XQuery/filter-2.xquery
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<result>
|
||||
<short>2 4 6 8 10</short>
|
||||
<long>2 4 6 8 10</long>
|
||||
</result>
|
||||
3
Task/Filter/XSLT/filter.xslt
Normal file
3
Task/Filter/XSLT/filter.xslt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<xsl:for-each select="nodes[@value mod 2 = 0]">
|
||||
<xsl:value-of select="@value" />
|
||||
</xsl:for-each>
|
||||
Loading…
Add table
Add a link
Reference in a new issue