default.txt 671 B

12345678910111213141516171819202122232425262728
  1. ;; Calculation of Hofstadter's male and female sequences as a list of pairs
  2. (define (hofstadter-male-female n)
  3. (letrec ((female (lambda (n)
  4. (if (= n 0)
  5. 1
  6. (- n (male (female (- n 1)))))))
  7. (male (lambda (n)
  8. (if (= n 0)
  9. 0
  10. (- n (female (male (- n 1))))))))
  11. (let loop ((i 0))
  12. (if (> i n)
  13. '()
  14. (cons (cons (female i)
  15. (male i))
  16. (loop (+ i 1)))))))
  17. (hofstadter-male-female 8)
  18. (define (find-first func lst)
  19. (call-with-current-continuation
  20. (lambda (return-immediately)
  21. (for-each (lambda (x)
  22. (if (func x)
  23. (return-immediately x)))
  24. lst)
  25. #f)))