Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
40
Task/Filter/BCPL/filter.bcpl
Normal file
40
Task/Filter/BCPL/filter.bcpl
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
get "libhdr"
|
||||
|
||||
// Copy every value for which p(x) is true from in to out
|
||||
// This will also work in place by setting out = in
|
||||
let filter(p, in, ilen, out, olen) be
|
||||
$( !olen := 0
|
||||
for i = 0 to ilen-1 do
|
||||
if p(in!i) do
|
||||
$( out!!olen := in!i
|
||||
!olen := !olen + 1
|
||||
$)
|
||||
$)
|
||||
|
||||
// Write N elements from vector
|
||||
let writevec(v, n) be
|
||||
for i = 0 to n-1 do writef("%N ", v!i)
|
||||
|
||||
let start() be
|
||||
$( // Predicates
|
||||
let even(n) = (n&1) = 0
|
||||
let mul3(n) = n rem 3 = 0
|
||||
|
||||
let nums = table 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
|
||||
let arr = vec 20
|
||||
let len = ?
|
||||
|
||||
writes("Numbers: ")
|
||||
writevec(nums, 15)
|
||||
|
||||
// Filter 'nums' into 'arr'
|
||||
filter(even, nums, 15, arr, @len)
|
||||
writes("*NEven numbers: ")
|
||||
writevec(arr, len)
|
||||
|
||||
// Filter 'arr' in place for multiples of 3
|
||||
filter(mul3, arr, len, arr, @len)
|
||||
writes("*NEven multiples of 3: ")
|
||||
writevec(arr, len)
|
||||
wrch('*N')
|
||||
$)
|
||||
Loading…
Add table
Add a link
Reference in a new issue