Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,2 @@
x:range[100]
{1- x mod 2}hfilter x

View 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');

View 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)

View 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

View file

@ -0,0 +1,2 @@
fun main(as: []int): []int =
filter (fn x => x%2 == 0) as

View 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

View 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

View 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)

View file

@ -0,0 +1 @@
100 seq filter(#isEven)

View 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;
]

View 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|...</@>
</@>
</@>

View 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

View 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()

View 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

View file

@ -0,0 +1 @@
evens(x(1))[i] := x[i] when x[i] mod 2 = 0;

View 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]

View file

@ -0,0 +1,3 @@
let numbers = [1,2,3,4,5,6]
let even_numbers = numbers.filter { $0 % 2 == 0 }
println(even_numbers)

View file

@ -0,0 +1 @@
(1,2,3,4,5,6,7,8,9) | select(. % 2 == 0)

View file

@ -0,0 +1 @@
[range(1;10)] | map( select(. % 2 == 0) )