fork download
  1. ; odometer
  2.  
  3. (define (next-char c)
  4. (integer->char (+ (char->integer c) 1)))
  5.  
  6. (define (next1 c)
  7. (cond ((char=? c #\Z) (values #\A #t))
  8. ((char=? c #\9) (values #\0 #t))
  9. (else (values (next-char c) #f))))
  10.  
  11. (define (next str)
  12. (let loop ((cs (reverse (string->list str))) (xs (list)) (carry? #f))
  13. (if (null? cs) (list->string (reverse xs))
  14. (call-with-values
  15. (lambda () (next1 (car cs)))
  16. (lambda (x carry?)
  17. (if carry? (loop (cdr cs) (cons x xs) #f)
  18. (list->string (append (reverse (cdr cs)) (cons x xs)))))))))
  19.  
  20. (display (next "123")) (newline)
  21. (display (next "199")) (newline)
  22. (display (next "999")) (newline)
  23. (display (next "ABC")) (newline)
  24. (display (next "FZZ")) (newline)
  25. (display (next "G7TS39")) (newline)
Success #stdin #stdout 0.03s 8196KB
stdin
Standard input is empty
stdout
124
200
000
ABD
GAA
G7TS40