Extended Straddling Checkerboard: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: more idiomatic version of decode)
 
Line 118: Line 118:


def decode:
def decode:
. as $s
{s: .} + checkerboard
| ($s|length) as $sc
| .ewords["FSL"] as $fsl
| checkerboard
| .res = ""
| .res = ""
| .figs = false
| .figs = false
| .i = 0
| until (.s == "";
| until (.i >= $sc;
.s[0:1] as $c
$s[.i:.i+1] as $c
| .ix = -1
| .ix = -1
| if .figs
| if .figs
then if $s[.i:.i+2] != .ewords["FSL"]
then if (.s | startswith($fsl) | not)
then .res += $c
then .res += $c
else .figs = false
else .figs = false
end
end
| .i += 2
| .s |= .[2:]
else .ix = (drow1|index($c))
else .ix = (drow1|index($c))
| if .ix and .ix >= 0
| if .ix and .ix >= 0
then .res += .dmap[drow1[.ix:.ix+1]]
then .res += .dmap[drow1[.ix:.ix+1]]
| .i += 1
| .s |= .[1:]
elif $c == "6"
elif $c == "6"
then .res += "CODE" + $s[.i+1:.i+4]
then .res += "CODE" + .s[1:4]
| .i += 4
| .s |= .[4:]
elif $c == "7" or $c == "8"
elif $c == "7" or $c == "8"
then $s[.i+1:.i+2] as $d
then .s[1:2] as $d
| .res += .dmap[$c + $d]
| .res += .dmap[$c + $d]
| .i += 2
| .s |= .[2:]
elif $c == "9"
elif $c == "9"
then $s[.i+1:.i+2] as $d
then .s[1:2] as $d
| if $d == "0"
| if $d == "0"
then .res += " "
then .res += " "
Line 154: Line 152:
else .res += .dwords[$c + $d]
else .res += .dwords[$c + $d]
end
end
| .i += 2
| .s |= .[2:]
end
end
end )
end )