; gcd: greatest common divisor; is a scheme primitive

; (gcd 24 18)  ; --> 6, because 6 is the biggest divisor of both 18 and 24

; Write a relatively prime function that takes two positive integers and
; returns #t if their gcd is 1, #f otherwise

(define (relatively-prime? a b)
  (= (gcd a b) 1))  ; (if expr #t #f) --> expr

; Write a function relprimes that takes a positive integer and a sentence
; of positive integers and keeps only those numbers in the sentence that
; are relatively prime to the first input
;
; Example:
; > (relprimes 6 '(1 4 6 10 13 15 19 21 35))
; '(1 13 19 35)

; Assuming x and n are defined...
; (lambda (x) (relatively-prime? n x))  is always a function
; (relatively-prime? n x)               is always boolean (#t or #f)

(define (relprimes n sent)
  (keep (lambda (x) (relatively-prime? n x)) sent))

(define (relprimes2 n sent)
  (define (relatively-prime-to-n? a)  ;
    (= (gcd a n) 1))  
  (keep relatively-prime? sent))

; Simplification reminder: (if expr #t #f) --> expr