4ステートバーコード
多くの郵便サービス(Royal Mail UK、Canada Post、US
Mailなど)では、4州のバーコードを使用してメールに関する情報をエンコードしています。
ASCII形式でレンダリングすると、次のようになります。
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
4ステートのバーコードはバーの行です。各バーは、上下左右に拡張でき、4つの可能性があります。つまり、各バーは基本的に4桁の数字を表します。
| | Bar: | | | | | | Digit: 0 1 2 3
このシンボルの問題点は、各バーコードが有効で異なるバーコードであることです。向きが間違っていると意味が大きく変わります。したがって、開始と停止のシーケンスが通常実装されているので、スキャナはどのように読み込まれるべきかを計算できます。
For the purpose of this challenge, we will be using the
start/stop sequence specified by Australia Post: each
barcode begins and ends with a 1 0
sequence.
チャレンジ
あなたの仕事は、正の整数 N
を与えて、それをASCII
4状態バーコードに変換するプログラムまたは関数を書くことです。各バー(スタート/ストップシーケンスを除く)は、
N
の基数4表現です。
例:
整数 19623
が与えられたら、最初にそれを基数4の表現 10302213
に変換します。
次に、各桁を対応する棒にマッピングします。
1 0 3 0 2 2 1 3 | | | | | | | | | | | | | | | |
最後に、開始/停止シーケンスを追加します。
Start: End: 1 0 1 0 | | | | | | | | | | | | | | | | | | | | | |
結果のバーコードは、プログラムの出力でなければなりません。
ルール:
- The input will be a positive integer, within the range of your
language’s standard integer size. - The output:
- May be either a list of lines, or a string containing
newlines. - May contain leading or trailing newlines/spaces, as long as the
shape remains intact. - Should show the barcode with the above format – it must use the
pipe character (|
) and space character () when drawing
bars, and there should be 1 space in between each upright bar.
- May be either a list of lines, or a string containing
- This is code-golf,
so the shortest program (in bytes) wins!
テストケース
4095:
| | | | | | | | | | | | | | | | | | | | | | | |
4096:
| | | | | | | | | | | | | |
7313145:
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
ベストアンサー
Python
3, 103 99 96 bytes
def f(i,r=[]):
while i_r=[' | ||||| ||'[i%4::4]]+r;i//=4
k='|| ',' | ';[*map(print,*k,*r,*k)]