28 lines
1.1 KiB
Text
28 lines
1.1 KiB
Text
V t = [[String(‘79’), ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’],
|
||
[String(‘’), ‘H’, ‘O’, ‘L’, ‘’, ‘M’, ‘E’, ‘S’, ‘’, ‘R’, ‘T’],
|
||
[String(‘3’), ‘A’, ‘B’, ‘C’, ‘D’, ‘F’, ‘G’, ‘I’, ‘J’, ‘K’, ‘N’],
|
||
[String(‘7’), ‘P’, ‘Q’, ‘U’, ‘V’, ‘W’, ‘X’, ‘Y’, ‘Z’, ‘.’, ‘/’]]
|
||
|
||
F straddle(s)
|
||
R multiloop_filtered(Array(s.uppercase()), :t, (c, l) -> c C l, (c, l) -> l[0]‘’:t[0][l.index(c)]).join(‘’)
|
||
|
||
F unstraddle(s)
|
||
[String] r
|
||
V si = 0
|
||
F next()
|
||
R @s[@si++]
|
||
L
|
||
I si == s.len
|
||
L.break
|
||
V c = s[si++]
|
||
I c C (:t[2][0], :t[3][0])
|
||
V i = [:t[2][0], :t[3][0]].index(c)
|
||
V n = :t[2 + i][:t[0].index(next())]
|
||
r [+]= I n == ‘/’ {next()} E n
|
||
E
|
||
r [+]= :t[1][:t[0].index(c)]
|
||
R r
|
||
|
||
V O = ‘One night-it was on the twentieth of March, 1888-I was returning’
|
||
print(‘Encoded: ’straddle(O))
|
||
print(‘Decoded: ’unstraddle(straddle(O)).join(‘’))
|