例の問題

効率とか気にしない感じで。

(use srfi-1)
(use srfi-42)

(define (candidates xs n)
  (if (>= 1 n) (map list xs)
      (append-map (lambda (x) (map (cut cons x <>) (candidates xs (- n 1)))) xs)))
  
(define (solve n)
  (list-ec (: e (candidates '("A" "C" "G" "T") n))
           (:let str (string-join e ""))
           (if (#/A{2}G/ str))
           str))

(solve 5) ; => ("AAAAG" "AAAGA" "AAAGC" "AAAGG" "AAAGT" "AAGAA" "AAGAC" "AAGAG" "AAGAT" "AAGCA" "AAGCC" "AAGCG" "AAGCT" "AAGGA" "AAGGC" "AAGGG" "AAGGT" "AAGTA" "AAGTC" "AAGTG" "AAGTT" "ACAAG" "AGAAG" "ATAAG" "CAAAG" "CAAGA" "CAAGC" "CAAGG" "CAAGT" "CCAAG" "CGAAG" "CTAAG" "GAAAG" "GAAGA" "GAAGC" "GAAGG" "GAAGT" "GCAAG" "GGAAG" "GTAAG" "TAAAG" "TAAGA" "TAAGC" "TAAGG" "TAAGT" "TCAAG" "TGAAG" "TTAAG")