Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(use gauche.sequence)
;; (xrotate '(x a b c d e) 3) -> (a b c x d e) etc.
(define (xrotate lis n)
`(,@(subseq lis 1 (+ n 1)) ,(car lis) ,@(drop lis (+ n 1))))
(define (digit->column n)
`(#\# ,@(xrotate '(#\o #\|) (div n 5)) #\# ,@(xrotate '(#\| #\o #\o #\o #\o) (mod n 5)) #\#))
(define (num->columns num width)
(map ($ digit->column $ digit->integer $) (format "~v,'0d" width num)))
(define *border* (make-list 10 #\#))
(define (soroban num :optional (width 8))
(for-each print (apply map string `(,*border* ,@(num->columns num width) ,*border*))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment