On Dec 17, 8:09 pm, Chouser <chou...@gmail.com> wrote:
>
> I don't think I agree with the premise of the question, that golf
> answers help anyone learn about other languages.
>
> But I can't deny that golfing is fun!
>
> (defn enc[s e](apply str(map(into{}(for[[o _ n](partition 3 4 e)][o n]))s)))
>
> I can't figure out how to edit your stackoverflow answer, but feel
> free to put my answer in there if you want.
>
> It may also be worth noting that to use the command line arguments,
> you'd just need to add:
>
> (apply enc *command-line-args*)
>
> --Chouser
As always you are very helpful, thanks Chouser!
There is a small problem with your solution, however. If the
character is not in the encoding your solution will just drop it from
the string. But you put me on the right track and here is what I came
up with. I could have also built a default map with each character
mapping to itself, and then doing an overriding union with the
encoding map, but I think this way is more clear (albeit a little
obfuscated in my opinion).
(defn enc [s e] (apply str (map #(or ((into{} (for [[o _ n] (partition
3 4 e)] [o n])) %) %) s)))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---