I'm still pretty fresh to Racket so a bit confused about this, i've created a drop-divisible and sieve-with function as shown below with some help but now need to use both to create a single function that finds all prime numbers with a given length of a list.
(define (drop-divisible x lst)
(cond
[(empty? lst) empty]
[(or (= x (first lst)) (< 0 (remainder (first lst) x)))
(cons (first lst) (drop-divisible x (rest lst)))]
[else (drop-divisible x (rest lst))]))
(define (sieve-with divisors lst)
(foldl (lambda (e acc) (drop-divisible e acc))
lst divisors))
this is one of the test cases i need to pass
(module+ test
(check-equal? (sieve 10) (list 2 3 5 7)))
so far ive tried to create a list using the parameter given with sieve to create a list of that size.
(define (sieve lst)
((sieve-with () (build-list (sub1 lst) (+ values 2)))))
getting stuck on how to get the divisors from just 10 in the test case. Thanks
I guess this is an assignment 1 from CS2613. It would be helpful to add an exact description of your problems:
You are required to write
drop-divisibleusing higher order functions (map,filter,foldland so on), with no explicit recursion. Yourdrop-divisibleis definitely recursive (and probably copied from this question).Function
sievewill callsieve-withwith two arguments: a list of divisors and a list of all numbers to be sieved. You will need functionrangeto create these lists and alsosqrtto get the square root of the given number.