Skip to content

Instantly share code, notes, and snippets.

@shirok
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirok/c9b26f0ffaab9f123bab to your computer and use it in GitHub Desktop.
Save shirok/c9b26f0ffaab9f123bab to your computer and use it in GitHub Desktop.
(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