;; ;; Scheme-program for computing Gus Wiseman's A340827 in https://oeis.org/A340827 ;; A340827 o=1: Number of strict integer partitions of n into divisors of n whose length also divides n. ;; Written by Antti Karttunen, 2023-02-22. ;; ;; We essentially employ the same algorithm as in the PARI-program: ;; (PARI) A340827(n, divsleft=List(divisors(n)), rest=n, len=0) = if(rest<=0, !rest && !(n%len), my(s=0, d); forstep(i=#divsleft, 1, -1, d = divsleft[i]; listpop(divsleft, i); if(rest>=d, s += A340827(n, divsleft, rest-d, 1+len))); (s)); ;; ;; This works with MIT/GNU Scheme microcode 15.3 (Image saved on Tuesday February 6, 2018 at 6:31:25 PM, Release 9.1.1 || Microcode 15.3 || Runtime 15.7 || SF 4.41). ;; (declare (usual-integrations)) ;; This is for the compiler of MIT/GNU Scheme. (define (divisors n) (let loop ((k n) (divs (list))) (cond ((zero? k) (reverse! divs)) ((zero? (modulo n k)) (loop (- k 1) (cons k divs))) (else (loop (- k 1) divs)) ) ) ) (define (A340827 n) (let foo ((divs (divisors n)) (rest n) (len 0)) (cond ((<= rest 0) (if (and (zero? rest) (zero? (modulo n len))) 1 0)) (else (let loop ((divs divs) (s 0)) (cond ((null? divs) s) ((>= rest (car divs)) (loop (cdr divs) (+ s (foo (cdr divs) (- rest (car divs)) (+ 1 len))) ) ) (else (loop (cdr divs) s)) ) ) ) ) ) ) ;; Works in MIT Scheme: (load-option 'format) (define (Anum->str Anum) (string-append "A" (string-pad-left (if (string? Anum) Anum (number->string Anum)) 6 #\0) ) ) (define (Anum->Afun Anum) (eval (string->symbol (string-downcase (Anum->str Anum))) user-initial-environment) ) (define (output-bfile Anum offset upto-n) (let* ((filename (format #f "b~a.txt" (string-tail (Anum->str Anum) 1))) (Afun (Anum->Afun Anum)) ) (call-with-output-file filename (lambda (outport) (let loop ((i offset)) (cond ((<= i upto-n) (format outport "~a ~a\n" i (Afun i)) (flush-output outport) (loop (+ 1 i)) ) ) ) ) ) editblurp ) ) (output-bfile 340827 1 2519)