Skip to content

Instantly share code, notes, and snippets.

@kui
Forked from valvallow/batz.dat
Last active July 8, 2020 08:07
Show Gist options
  • Save kui/5245790 to your computer and use it in GitHub Desktop.
Save kui/5245790 to your computer and use it in GitHub Desktop.
0 00 0000000
01011011111110
010111111111000
0111111111111110
011111111111100
01113113111111110
0101310011111110
00100031133100
030333133110
0003033330000
0110337330000
01103333011000
001033007703330
0101000110033330
033011011330113330
033301111333111330
0333 077033311130
000 01110000000
01033010
0033300
011111110
01111110
711110
07771170
000000
00
00000 00770
0777770000077070
0711117777700170
071777777011170
07700007771170
070011110777170
0700111111077770
07010311111077770
07001003003107770
0700303300307770
07030330330770
0703333370770
0070333317700
077010011177770
07117107101177770
000117710330117770
033011010330110770
033071071011100070
001017711100000070
070011011111100070
070000003330000070
0700011111110070
07770111110770
000111111000
000000
0000 00000 0
02222022222000020
022222222222222220
02022222222222220
0226662266222020
0206662266262220
00333022222220
000322222220
032032332220
000303333322000
06663333332066660
0603333000222020
022003060003330
033320002033023330
033302022033322330
0330 022003332230
00 060066000000
06600660
0603300
03333000
0222222220
06666660
0266660
02226620
000000
00
00330
033320
0033320
003333220
000000033332220
0333333332222220
02222333322220
0002222333200
00002222220
030000022220
00300300002220
04000030000400
040000000000040
044400044444440
00444444400040
0330444440044440
03304444033044440
004404403304440
040440040044440
040444440044440
044044440044440
044404444044440
0444400444044040
044444444444004440
0000000000000000
00000
000002020
033202200
0000000000000
00200772000
0007332000330
0000000000303333222220
0732333330303333333330
0000000000202220202220
00322020222323222000
030000002222222220300
000003000000000000020
007332323222222222300
032200000000000002220
020002232232232000000
0000000000000000200
0202000000000000000
0300002000200020030
0020022002200220020
003000000000000200
0003233233233200
0000000000000
0000
00077770
00777777770
0077777777770
07777777770770
077000077777070
070011110777770
0700111111077770
07010311111077770
07001003003107770
0700303300307770
07030330330770
0703333370770
00070333307700
0177070000777770
01110777770000770
01177007701777070
01777777701117770
01117777701177770
01177777701777770
01770777701117770
01110777701177770
0170771770171770
0101711711011710
0111111111011110
000000000 0000
#!/usr/local/bin/gosh
(use gauche.parseopt)
(define-constant ANSI_ESCAPE_BG_COLOR_BASE 40)
(define (ansi-escape str color-num)
(apply string-append
(map (apply$ string)
(list `(#\escape #\[ ,@(string->list (x->string color-num)) #\m)
(string->list str)
`(#\escape #\[ ,@'(#\0) #\m)))))
(define (draw ls)
(for-each
(^l (for-each
(^x (if-let1 n (string->number x)
(display (ansi-escape " " (+ n ANSI_ESCAPE_BG_COLOR_BASE)))
(display " ")))
l)
(print))
ls))
(define (usage cmd)
(print "usage: " cmd " file1.dat file2.dat ... filen.dat")
(print "exapmle: % echo \'0123 4567\' | " cmd)
(print (draw '(("0" "1" "2" "3" " " "4" "5" "6" "7"))))
(exit))
(define (input->list)
(define (line->list val)
(map string (string->list val)))
(let rec ((acc '()))
(let1 val (read-line)
(if (eof-object? val)
(reverse acc)
(rec (cons (line->list val) acc))))))
(define (list->double ls)
(fold-right (^ (x acc)
(cons x (cons x acc)))
'()
ls))
(define (main args)
(let-args (cdr args)
((help "h|help" => (cut usage (car args)))
(else (opt . _)
(print "Unknown option : " opt)
(usage (car args)))
. rest)
(let1 data (if (null? rest)
(input->list)
(apply map (^ rows (apply append rows))
(map (cut with-input-from-file <> input->list)
rest)))
(print (draw (map list->double data))))))

Gauche 持ってないけど試しに実行してみたい時は:

ruby -ne 'print $_.gsub(/ /){"  "}.gsub(/\d/){"\e[4#{$&}m  \e[0m"}' dousi.dat
# もしくは
ruby -ne 'print $_.gsub(/ /){"0"}.gsub(/\d/){"\e[4#{$&}m  \e[0m"}' dousi.dat

perl などでも似たようなワンライナでいけるはず。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment