Write a function that accepts a rectangular grid of ids in any reasonable format, for example a multi-line string:
IIILOO
ILLLOO
and a string or list of box drawing charcters such as:
' ═║╔╗╚╝╠╣╦╩╬'
or
[0x20, 0x2550, 0x2551, 0x2554, 0x2557, 0x255a, 0x255d, 0x2560, 0x2563, 0x2566, 0x2569, 0x256c']
(see below for more details) and returns a pretty printed version, as such:
╔═══════════╦═══╦═══════╗
║ ║ ║ ║
║ ╔═══════╝ ║ ║
║ ║ ║ ║
╚═══╩═══════════╩═══════╝
i.e. a rectangle made out of the box drawing characters, where each border indicates the border of each polyomino.
╔═══════════╦═══╦═══════╗
║ I I I ║ L ║ O O ║
║ ╔═══════╝ ║ ║
║ I ║ L L L ║ O O ║
╚═══╩═══════════╩═══════╝
Rules
Shortest submission in bytes per language wins. Standard rules apply.
Note that to leave room for annotations and as the characters used are half width each unit square is 2x4 (3x5 but boundary fields are shared with neighbouring squares) characters in the output.
You may assume that input is clean rectangular and ids are unique to orthogonally connected regions.
To avoid any unicode related issues I have decided to provide the box drawing characters as an input. This may be any flat container holding the characters in any order as long as it contains
- each character exactly once and
- only these characters (no fillers)
- access is sequential or per index only (no sophisticated lookup tables)
More examples:
In:
XXXSS
RXSSL
ROOOL
RROLL
' ═║╔╗╚╝╠╣╦╩╬'
Out:
╔═══════════╦═══════╗
║ ║ ║
╠═══╗ ╔═══╝ ╔═══╣
║ ║ ║ ║ ║
║ ╠═══╩═══════╣ ║
║ ║ ║ ║
║ ╚═══╗ ╔═══╝ ║
║ ║ ║ ║
╚═══════╩═══╩═══════╝
In:
1220003
2240503
2444666
' ═║╔╗╚╝╠╣╦╩╬'
Out:
╔═══╦═══════╦═══════════╦═══╗
║ ║ ║ ║ ║
╠═══╝ ╔═══╣ ╔═══╗ ║ ║
║ ║ ║ ║ ║ ║ ║
║ ╔═══╝ ╚═══╬═══╩═══╩═══╣
║ ║ ║ ║
╚═══╩═══════════╩═══════════╝