PasteRack.org
Paste # 15194
2022-06-18 00:43:00

Fork as a new paste.

Paste viewed 881 times.


Embed:

  1. #lang racket
  2.  
  3. (define (reference-next r)
  4.   (list->string
  5.    (match (string->list r)
  6.      [(list #\Z #\Z #\Z #\9 #\9 #\9) (error "ZZZ999 is the last matter reference")]
  7.      [(list a #\Z #\Z #\9 #\9 #\9) (list (next-char a) #\A #\A #\1 #\7 #\3)]
  8.      [(list a b #\Z #\9 #\9 #\9) (list a (next-char b) #\A #\1 #\7 #\3)]
  9.      [(list a b c #\9 #\9 #\9) (list a b (next-char c) #\1 #\7 #\3)]
  10.      [(list a b c d #\9 #\9) (list a b c (next-char d) #\0 #\0)]
  11.      [(list a b c d e #\9) (list a b c d (next-char e) #\0)]
  12.      [(list a b c d e f) (list a b c d e (next-char f))])))
  13.  
  14. (define (references from)
  15.   (cond
  16.     [(equal? from "ZZZ999") (list "ZZZ999")]
  17.     [else (cons from (references (reference-next from)))]))
  18.  
  19. (define (all-references)
  20.   (references "CLS173"))

=>