Sha256: 301e256d21a6e17c96658de808797fca41203a3dde0d8910a45921f29b49d021
Contents?: true
Size: 989 Bytes
Versions: 310
Compression:
Stored size: 989 Bytes
Contents
-module(example). -export([encode/1, decode/1, test_version/0]). encode(String) -> join(chunk(convert(String), 5)). decode(String) -> convert(String). test_version() -> 1. %% Basic conversion routines convert(String) -> lists:filtermap(fun encode_char/1, String). encode_char(C) when C >= $A, C =< $Z -> %% shift to lower-case {true, $Z - C + $a}; encode_char(C) when C >= $a, C =< $z -> {true, $z - C + $a}; encode_char(C) when C >= $0, C =< $9 -> {true, C}; encode_char(_C) -> false. %% %% Functions for converting to word chunks of 5 characters join(Lists) -> string:join(Lists, " "). chunk(String, N) -> lists:reverse(chunk( lists:split(min(length(String), N), String), [], N)). chunk({Last, []}, Accum, _N) -> [Last] ++ Accum; chunk({Next, Remainder}, Accum, N) -> chunk( lists:split(min(length(Remainder), N), Remainder), [Next] ++ Accum, N). %%
Version data entries
310 entries across 310 versions & 1 rubygems