September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
2
Task/Filter/APL/filter.apl
Normal file
2
Task/Filter/APL/filter.apl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(0=2|x)/x←⍳20
|
||||
2 4 6 8 10 12 14 16 18 20
|
||||
|
|
@ -1,30 +1,40 @@
|
|||
-- filter :: (a -> Bool) -> [a] -> [a]
|
||||
-- filter :: (a -> Int -> Bool) -> [a] -> [a]
|
||||
-- filter :: (a -> Int -> [a] -> Bool) -> [a] -> [a]
|
||||
on filter(f, xs)
|
||||
script mf
|
||||
property lambda : f
|
||||
end script
|
||||
|
||||
set lst to {}
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to item i of xs
|
||||
if mf's lambda(v, i, xs) then
|
||||
set end of lst to v
|
||||
end if
|
||||
end repeat
|
||||
return lst
|
||||
tell mReturn(f)
|
||||
set lst to {}
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to item i of xs
|
||||
if |λ|(v, i, xs) then set end of lst to v
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end filter
|
||||
|
||||
|
||||
-- Ordinary AppleScript predicate function, rather than a script object
|
||||
-- TEST -----------------------------------------------------------------------
|
||||
|
||||
-- isEven :: (a -> Bool)
|
||||
on isEven(x)
|
||||
x mod 2 = 0
|
||||
end isEven
|
||||
|
||||
set lstRange to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
||||
on run
|
||||
|
||||
filter(isEven, lstRange)
|
||||
filter(isEven, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
||||
|
||||
-- {0, 2, 4, 6, 8, 10}
|
||||
end run
|
||||
|
||||
-- GENERIC FUNCTION -----------------------------------------------------------
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
|
|
|||
58
Task/Filter/Batch-File/filter.bat
Normal file
58
Task/Filter/Batch-File/filter.bat
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set numberarray=1 2 3 4 5 6 7 8 9 10
|
||||
for %%i in (%numberarray%) do (
|
||||
set /a tempcount+=1
|
||||
set numberarray!tempcount!=%%i
|
||||
)
|
||||
|
||||
echo Filtering all even numbers from numberarray into newarray...
|
||||
call:filternew numberarray
|
||||
echo numberarray - %numberarray%
|
||||
echo newarray -%newarray%
|
||||
echo.
|
||||
echo Filtering numberarray so that only even entries remain...
|
||||
call:filterdestroy numberarray
|
||||
echo numberarray -%numberarray%
|
||||
pause>nul
|
||||
exit /b
|
||||
|
||||
:filternew
|
||||
set arrayname=%1
|
||||
call:arraylength %arrayname%
|
||||
set tempcount=0
|
||||
for /l %%i in (1,1,%length%) do (
|
||||
set /a cond=!%arrayname%%%i! %% 2
|
||||
if !cond!==0 (
|
||||
set /a tempcount+=1
|
||||
set newarray!tempcount!=!%arrayname%%%i!
|
||||
set newarray=!newarray! !%arrayname%%%i!
|
||||
)
|
||||
)
|
||||
exit /b
|
||||
|
||||
:filterdestroy
|
||||
set arrayname=%1
|
||||
call:arraylength %arrayname%
|
||||
set tempcount=0
|
||||
set "%arrayname%="
|
||||
for /l %%i in (1,1,%length%) do (
|
||||
set /a cond=!%arrayname%%%i! %% 2
|
||||
if !cond!==0 (
|
||||
set /a tempcount+=1
|
||||
set %arrayname%!tempcount!=!%arrayname%%%i!
|
||||
set %arrayname%=!%arrayname%! !%arrayname%%%i!
|
||||
)
|
||||
)
|
||||
exit /b
|
||||
|
||||
:arraylength
|
||||
set tempcount=0
|
||||
set lengthname=%1
|
||||
set length=0
|
||||
:lengthloop
|
||||
set /a tempcount+=1
|
||||
if "!%lengthname%%tempcount%!"=="" exit /b
|
||||
set /a length+=1
|
||||
goto lengthloop
|
||||
43
Task/Filter/Gambas/filter.gambas
Normal file
43
Task/Filter/Gambas/filter.gambas
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
sRandom As New String[]
|
||||
'______________________________________________________________________________________________________
|
||||
Public Sub Main()
|
||||
Dim siCount As Short
|
||||
|
||||
For siCount = 0 To 19
|
||||
sRandom.Add(Rand(1, 100))
|
||||
Next
|
||||
|
||||
Print sRandom.join(",")
|
||||
|
||||
NewArray
|
||||
Destructive
|
||||
|
||||
End
|
||||
'______________________________________________________________________________________________________
|
||||
Public Sub NewArray() 'Select certain elements from an array into a new array in a generic way
|
||||
Dim sEven As New String[]
|
||||
Dim siCount As Short
|
||||
|
||||
For siCount = 0 To sRandom.Max
|
||||
If Even(sRandom[siCount]) Then sEven.Add(sRandom[siCount])
|
||||
Next
|
||||
|
||||
Print sEven.join(",")
|
||||
|
||||
End
|
||||
'______________________________________________________________________________________________________
|
||||
Public Sub Destructive() 'Give a second solution which filters destructively
|
||||
Dim siIndex As New Short[]
|
||||
Dim siCount As Short
|
||||
|
||||
For siCount = 0 To sRandom.Max
|
||||
If Odd(sRandom[siCount]) Then siIndex.Add(siCount)
|
||||
Next
|
||||
|
||||
For siCount = siIndex.max DownTo 0
|
||||
sRandom.Extract(siIndex[siCount], 1)
|
||||
Next
|
||||
|
||||
Print sRandom.join(",")
|
||||
|
||||
End
|
||||
14
Task/Filter/JavaScript/filter-5.js
Normal file
14
Task/Filter/JavaScript/filter-5.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// isEven :: Int -> Bool
|
||||
const isEven = n => n % 2 === 0;
|
||||
|
||||
|
||||
// TEST
|
||||
|
||||
return [1,2,3,4,5,6,7,8,9]
|
||||
.filter(isEven);
|
||||
|
||||
// [2, 4, 6, 8]
|
||||
})();
|
||||
1
Task/Filter/JavaScript/filter-6.js
Normal file
1
Task/Filter/JavaScript/filter-6.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
[2, 4, 6, 8]
|
||||
13
Task/Filter/Kotlin/filter.kotlin
Normal file
13
Task/Filter/Kotlin/filter.kotlin
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// version 1.0.5-2
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val array = arrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
|
||||
println(array.joinToString(" "))
|
||||
|
||||
val filteredArray = array.filter{ it % 2 == 0 }
|
||||
println(filteredArray.joinToString(" "))
|
||||
|
||||
val mutableList = array.toMutableList()
|
||||
mutableList.retainAll { it % 2 == 0 }
|
||||
println(mutableList.joinToString(" "))
|
||||
}
|
||||
3
Task/Filter/Maple/filter.maple
Normal file
3
Task/Filter/Maple/filter.maple
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
evennum:=proc(nums::list(integer))
|
||||
return select(x->type(x, even), nums);
|
||||
end proc;
|
||||
31
Task/Filter/OoRexx/filter.rexx
Normal file
31
Task/Filter/OoRexx/filter.rexx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
Call random ,,1234567
|
||||
a=.array~new
|
||||
b=.array~new
|
||||
Do i=1 To 10
|
||||
a[i]=random(1,9999)
|
||||
End
|
||||
Say 'Unfiltered values:' a~makestring(line,' ')
|
||||
/* copy even numbers to array b */
|
||||
j=0
|
||||
Do i=1 to 10
|
||||
If filter(a[i]) Then Do
|
||||
j = j + 1
|
||||
b[j]=a[i]
|
||||
End
|
||||
end
|
||||
Say 'Filtered values (in second array): ' b~makestring(line,' ')
|
||||
/* destructive filtering: copy within array a */
|
||||
j=0
|
||||
Do i=1 to 10
|
||||
If filter(a[i]) Then Do
|
||||
j = j + 1
|
||||
a[j]=a[i]
|
||||
End
|
||||
end
|
||||
/* destructive filtering: delete the remaining elements */
|
||||
Do i=10 To j+1 By -1
|
||||
a~delete(i)
|
||||
End
|
||||
Say 'Filtered values (destructive filtering):' a~makestring(line,' ')
|
||||
Exit
|
||||
filter: Return arg(1)//2=0
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<@ LETCNWLSTLIT>numbers|1 2 3 4 5 6 7 8 9 10 11 12</@>
|
||||
<@ DEFLST>evens</@>
|
||||
<@ ENULSTLIT>numbers|
|
||||
<@ TSTEVEELTLST>...</@>
|
||||
<@ IFF>
|
||||
<@ LETLSTELTLST>evens|...</@>
|
||||
</@>
|
||||
</@>
|
||||
|
|
@ -1,9 +1,3 @@
|
|||
# Integer#even? is new to Ruby 1.8.7.
|
||||
# Define it for older Ruby.
|
||||
unless Integer.method_defined? :even?
|
||||
class Integer
|
||||
def even?
|
||||
self % 2 == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
ary = [1, 2, 3, 4, 5, 6]
|
||||
ary.select! {|elem| elem.even?}
|
||||
p ary # => [2, 4, 6]
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
ary = [1, 2, 3, 4, 5, 6]
|
||||
ary.select! {|elem| elem.even?}
|
||||
p ary # => [2, 4, 6]
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
# Array#select! is new to Ruby 1.9.2.
|
||||
# Define it for older Ruby.
|
||||
unless Array.method_defined? :select!
|
||||
class Array
|
||||
def select!
|
||||
enum_for(:select!) unless block_given?
|
||||
delete_if { |elem| not yield elem }
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
val ary = [1,2,3,4,5,6];
|
||||
List.filter (fn x => x mod 2 = 0) ary
|
||||
9
Task/Filter/Stata/filter.stata
Normal file
9
Task/Filter/Stata/filter.stata
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
mata
|
||||
a=2,9,4,7,5,3,6,1,8
|
||||
|
||||
// Select even elements of a
|
||||
select(a,mod(a,2):==0)
|
||||
|
||||
// Select the indices of even elements of a
|
||||
selectindex(mod(a,2):==0)
|
||||
end
|
||||
3
Task/Filter/Zkl/filter.zkl
Normal file
3
Task/Filter/Zkl/filter.zkl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
T(1,4,9,16,25,36,"37",49,64,81,100, True,self)
|
||||
.filter(fcn(n){(0).isType(n) and n.isOdd})
|
||||
//-->L(1,9,25,49,81)
|
||||
Loading…
Add table
Add a link
Reference in a new issue