Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 330698b
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
#!/usr/bin/env lsc | |||
|
|||
require! fs | |||
|
|||
c2p = {}; p2c = [] | |||
pin-p = {} | |||
p-count = 0 | |||
|
|||
for l in "#{fs.read-file-sync 'Mandarin.txt'}" / /\n/ | |||
[code, pin] = l / /\s+/ | |||
continue unless code is /^....$/ # BMP | |||
char = String.fromCharCode parseInt code, 16 | |||
p = (pin-p[pin] ?= p-count++) | |||
c2p[char] = p | |||
p2c[p] ||= "" | |||
p2c[p] += char | |||
|
|||
ring = '' | |||
for p, cs of p2c | |||
if cs.length is 1 | |||
p2c[p] = 0 | |||
delete c2p[cs.0] | |||
else | |||
ring += p2c[p] + p2c[p].0 | |||
|
|||
#console.log ring | |||
rev = '' | |||
``for (var i = ring.length - 1; i >= 0; rev += ring[i--]) {}`` | |||
|
|||
encode = -> (* '') <| for c in it | |||
idx = ring.index-of c | |||
if idx is -1 then c else ring.char-at idx + 1 | |||
|
|||
decode = -> (* '') <| for c in it | |||
idx = rev.index-of c | |||
if idx is -1 then c else rev.char-at idx + 1 | |||
|
|||
#console.log encode "主席:黃委員還是堅持刪減200萬?但我們委員從原先的全刪,改為一成,後來又改為5%,現在又改為500萬,而經過本席折 衝,建議減列300萬。我再最後一次詢問各位,是否互相折衝一下,減列300萬?" | |||
#console.log decode "嘱棤:黄娓园鍰昰奸歭剼湕200蟃?僤捰们娓园悰厡嘕的啳剼,絠煟伊承,洉俫右絠煟5%,県扗右絠煟500蟃,耏经㳀楍棤摺 蹖,徤讛湕劣300蟃。捰在栬洉伊絘询妏嗰卫,昰殕冱箱摺蹖伊吓,湕劣300蟃?" | |||
console.log encode "林書豪真的沒有講過這句話" | |||
|
330698b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
330698b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. 8d1ae98