Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
2
Task/Filter/AntLang/filter.antlang
Normal file
2
Task/Filter/AntLang/filter.antlang
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
x:range[100]
|
||||
{1- x mod 2}hfilter x
|
||||
15
Task/Filter/Apex/filter.apex
Normal file
15
Task/Filter/Apex/filter.apex
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
List<Integer> integers = new List<Integer>{1,2,3,4,5};
|
||||
Set<Integer> evenIntegers = new Set<Integer>();
|
||||
for(Integer i : integers)
|
||||
{
|
||||
if(math.mod(i,2) == 0)
|
||||
{
|
||||
evenIntegers.add(i);
|
||||
}
|
||||
}
|
||||
system.assert(evenIntegers.size() == 2, 'We should only have two even numbers in the set');
|
||||
system.assert(!evenIntegers.contains(1), '1 should not be a number in the set');
|
||||
system.assert(evenIntegers.contains(2), '2 should be a number in the set');
|
||||
system.assert(!evenIntegers.contains(3), '3 should not be a number in the set');
|
||||
system.assert(evenIntegers.contains(4), '4 should be a number in the set');
|
||||
system.assert(!evenIntegers.contains(5), '5 should not be a number in the set');
|
||||
16
Task/Filter/EchoLisp/filter.echolisp
Normal file
16
Task/Filter/EchoLisp/filter.echolisp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
(iota 12) → { 0 1 2 3 4 5 6 7 8 9 10 11 }
|
||||
|
||||
;; lists
|
||||
(filter even? (iota 12))
|
||||
→ (0 2 4 6 8 10)
|
||||
|
||||
;; array (non destructive)
|
||||
(vector-filter even? #(1 2 3 4 5 6 7 8 9 10 11 12 13))
|
||||
→ #( 2 4 6 8 10 12)
|
||||
|
||||
;; sequence, infinite, lazy
|
||||
(lib 'sequences)
|
||||
(define evens (filter even? [0 ..]))
|
||||
|
||||
(take evens 12)
|
||||
→ (0 2 4 6 8 10 12 14 16 18 20 22)
|
||||
63
Task/Filter/FreeBASIC/filter.freebasic
Normal file
63
Task/Filter/FreeBASIC/filter.freebasic
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Type FilterType As Function(As Integer) As Boolean
|
||||
|
||||
Function isEven(n As Integer) As Boolean
|
||||
Return n Mod 2 = 0
|
||||
End Function
|
||||
|
||||
Sub filterArray(a() As Integer, b() As Integer, filter As FilterType)
|
||||
If UBound(a) = -1 Then Return '' empty array
|
||||
Dim count As Integer = 0
|
||||
Redim b(0 To UBound(a) - LBound(a))
|
||||
For i As Integer = LBound(a) To UBound(a)
|
||||
If filter(a(i)) Then
|
||||
b(count) = a(i)
|
||||
count += 1
|
||||
End If
|
||||
Next
|
||||
|
||||
If count > 0 Then Redim Preserve b(0 To count - 1) '' trim excess elements
|
||||
End Sub
|
||||
|
||||
' Note that da() must be a dynamic array as static arrays can't be redimensioned
|
||||
Sub filterDestructArray(da() As Integer, filter As FilterType)
|
||||
If UBound(da) = -1 Then Return '' empty array
|
||||
Dim count As Integer = 0
|
||||
For i As Integer = LBound(da) To UBound(da)
|
||||
If i > UBound(da) - count Then Exit For
|
||||
If Not filter(da(i)) Then '' remove this element by moving those still to be examined down one
|
||||
For j As Integer = i + 1 To UBound(da) - count
|
||||
da(j - 1) = da(j)
|
||||
Next j
|
||||
count += 1
|
||||
i -= 1
|
||||
End If
|
||||
Next i
|
||||
|
||||
If count > 0 Then
|
||||
Redim Preserve da(LBound(da) To UBound(da) - count) '' trim excess elements
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Dim n As Integer = 12
|
||||
Dim a(1 To n) As Integer '' creates dynamic array as upper bound is a variable
|
||||
For i As Integer = 1 To n : Read a(i) : Next
|
||||
Dim b() As Integer '' array to store results
|
||||
filterArray a(), b(), @isEven
|
||||
Print "The even numbers are (in new array) : ";
|
||||
For i As Integer = LBound(b) To UBound(b)
|
||||
Print b(i); " ";
|
||||
Next
|
||||
Print : Print
|
||||
filterDestructArray a(), @isEven
|
||||
Print "The even numbers are (in original array) : ";
|
||||
For i As Integer = LBound(a) To UBound(a)
|
||||
Print a(i); " ";
|
||||
Next
|
||||
Print : Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
End
|
||||
|
||||
Data 1, 2, 3, 7, 8, 10, 11, 16, 19, 21, 22, 27
|
||||
2
Task/Filter/Futhark/filter.futhark
Normal file
2
Task/Filter/Futhark/filter.futhark
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fun main(as: []int): []int =
|
||||
filter (fn x => x%2 == 0) as
|
||||
3
Task/Filter/Lasso/filter-1.lasso
Normal file
3
Task/Filter/Lasso/filter-1.lasso
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
local(original = array(1,2,3,4,5,6,7,8,9,10))
|
||||
local(evens = (with item in #original where #item % 2 == 0 select #item) -> asstaticarray)
|
||||
#evens
|
||||
3
Task/Filter/Lasso/filter-2.lasso
Normal file
3
Task/Filter/Lasso/filter-2.lasso
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
local(original = array(1,2,3,4,5,6,7,8,9,10))
|
||||
with item in #original where #item % 2 != 0 do #original ->removeall(#item)
|
||||
#original
|
||||
7
Task/Filter/Nim/filter.nim
Normal file
7
Task/Filter/Nim/filter.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import sequtils
|
||||
|
||||
let values = @[0,1,2,3,4,5,6,7,8,9]
|
||||
|
||||
let evens = values.filter(proc (x: int): bool = x mod 2 == 0)
|
||||
|
||||
let odds = values.filterIt(it mod 2 == 1)
|
||||
1
Task/Filter/Oforth/filter.oforth
Normal file
1
Task/Filter/Oforth/filter.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
100 seq filter(#isEven)
|
||||
11
Task/Filter/PHL/filter.phl
Normal file
11
Task/Filter/PHL/filter.phl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module var;
|
||||
|
||||
extern printf;
|
||||
|
||||
@Integer main [
|
||||
var arr = 1..9;
|
||||
var evens = arr.filter(#(i) i % 2 == 0);
|
||||
printf("%s\n", evens::str);
|
||||
|
||||
return 0;
|
||||
]
|
||||
8
Task/Filter/Peloton/filter.peloton
Normal file
8
Task/Filter/Peloton/filter.peloton
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|...</@>
|
||||
</@>
|
||||
</@>
|
||||
9
Task/Filter/Phix/filter-1.phix
Normal file
9
Task/Filter/Phix/filter-1.phix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function filternd(sequence array, integer filterid)
|
||||
sequence res = {}
|
||||
for i=1 to length(array) do
|
||||
if call_func(filterid,{array[i]}) then
|
||||
res = append(res,array[i])
|
||||
end if
|
||||
end for
|
||||
return res
|
||||
end function
|
||||
26
Task/Filter/Phix/filter-2.phix
Normal file
26
Task/Filter/Phix/filter-2.phix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
function filterd(sequence a, integer filterid)
|
||||
integer l = 0
|
||||
for i=1 to length(a) do
|
||||
if call_func(filterid,{a[i]}) then
|
||||
l += 1
|
||||
a[l] = a[i]
|
||||
end if
|
||||
end for
|
||||
return a[1..l]
|
||||
end function
|
||||
|
||||
function even(integer i)
|
||||
return and_bits(i,1)=0
|
||||
end function
|
||||
constant r_even = routine_id("even")
|
||||
|
||||
procedure main()
|
||||
sequence s = tagset(10), t
|
||||
t = filterd(s,r_even)
|
||||
?s
|
||||
?t
|
||||
-- automatic pass by reference occurs here for s:
|
||||
s = filterd(s,r_even)
|
||||
?s
|
||||
end procedure
|
||||
main()
|
||||
12
Task/Filter/Ring/filter.ring
Normal file
12
Task/Filter/Ring/filter.ring
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
aList = [1, 2, 3, 4, 5, 6]
|
||||
bArray = list(3)
|
||||
see evenSelect(aList)
|
||||
|
||||
func evenSelect aArray
|
||||
i = 0
|
||||
for n = 1 to len(aArray)
|
||||
if (aArray[n] % 2) = 0
|
||||
i = i + 1
|
||||
bArray[i] = aArray[n] ok
|
||||
next
|
||||
return bArray
|
||||
1
Task/Filter/SequenceL/filter.sequencel
Normal file
1
Task/Filter/SequenceL/filter.sequencel
Normal file
|
|
@ -0,0 +1 @@
|
|||
evens(x(1))[i] := x[i] when x[i] mod 2 = 0;
|
||||
9
Task/Filter/Sidef/filter.sidef
Normal file
9
Task/Filter/Sidef/filter.sidef
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
var arr = [1,2,3,4,5];
|
||||
|
||||
# Creates a new array
|
||||
var new = arr.grep {|i| i %% 2};
|
||||
say new.dump; # => [2, 4]
|
||||
|
||||
# Destructive (at variable level)
|
||||
arr.grep! {|i| i %% 2};
|
||||
say arr.dump; # => [2, 4]
|
||||
3
Task/Filter/Swift/filter.swift
Normal file
3
Task/Filter/Swift/filter.swift
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
let numbers = [1,2,3,4,5,6]
|
||||
let even_numbers = numbers.filter { $0 % 2 == 0 }
|
||||
println(even_numbers)
|
||||
1
Task/Filter/jq/filter-1.jq
Normal file
1
Task/Filter/jq/filter-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
(1,2,3,4,5,6,7,8,9) | select(. % 2 == 0)
|
||||
1
Task/Filter/jq/filter-2.jq
Normal file
1
Task/Filter/jq/filter-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
[range(1;10)] | map( select(. % 2 == 0) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue