diff --git a/scheme/Makefile b/scheme/Makefile index 192354b..5ad8652 100644 --- a/scheme/Makefile +++ b/scheme/Makefile @@ -27,5 +27,8 @@ v6: run6: ./main +run7: + chez --optimize-level 3 -q --script main_chez_optimized.scm + clean: rm main main.db main.o1 diff --git a/scheme/main_chez_optimized.scm b/scheme/main_chez_optimized.scm new file mode 100644 index 0000000..7a4be07 --- /dev/null +++ b/scheme/main_chez_optimized.scm @@ -0,0 +1,30 @@ +;(define MAX-N 10000) +(define MAX-N 440000000) + +(define cache + (list->fxvector + (cons + 0 + (let loop ((i 1)) + (if (> i 10) + '() + (cons (expt i i) + (loop (+ i 1)))))))) + +(define (munchausen? num) + (let loop ((n num) + (total 0)) + (cond ((fx> total num) #f) + ((fx> n 0) + (loop (fxquotient n 10) + (fx+ total + (fxvector-ref cache + (fxremainder n 10))))) + (else (fx= num total))))) + +(let loop ((i 0)) + (when (munchausen? i) + (display i) + (newline)) + (when (fx< i MAX-N) + (loop (fx+ i 1))))