Rot-13: Difference between revisions

865 bytes added ,  9 months ago
added my own Hylang implementation, based upon python fileinput for the unixlike behaviour
(added my own Hylang implementation, based upon python fileinput for the unixlike behaviour)
Line 2,598:
* the setup exploits the ordered cset variables &lcase and &ucase coercing them into strings
* the rot13 mapping string is then aggregated with strings taken by offsetting into double length values to avoid unnecessary and messy rotation
 
=={{header|Hy}}==
<syntaxhighlight lang="hy">#!/usr/bin/env hy
(require hyrule [defmain])
 
(setv lowers (lfor *x* (range 26)
(chr (+ *x* (ord "a"))))) ; generate latin lower 26 chars
(setv uppers (list (map str.upper lowers))) ; and the upper case
(setv lowers (list (map ord lowers))) ; convert to unicode codepoints
(setv uppers (list (map ord uppers)))
(setv translations ; a dictionary with from->to
(dict (zip ; codepoint mapping
(+ lowers uppers)
(+ (cut lowers 13 None)
(cut lowers 0 13)
(cut uppers 13 None)
(cut uppers 0 13)))))
 
(defn rot13 [string]
(return (.translate string translations)))
 
(defmain []
(import fileinput)
(for [line (fileinput.input)]
(print (rot13 line) :end "")))
</syntaxhighlight>
 
=={{header|Insitux}}==
3

edits