(use util.combinations) (define K (read)) (define s 0) (define (s+) (set! s (+ s 1))) (define (modK? ls) (zero? (remainder (fold (^(a s) (+ (* s 10) a)) 0 ls) K))) (permutations-for-each (^a (if (modK? a) (s+))) (iota 8 1)) (print s)