Created
October 17, 2017 22:24
-
-
Save najibghadri/bd9f8c8aab78ae9497a1ec5e6a32fa1d to your computer and use it in GitHub Desktop.
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
-module(khf1). | |
-author('najibg96@gmail.com'). | |
-vsn('2017-10-17'). | |
-export([cella/2]). | |
cella(S, I) -> | |
M = length(S), | |
K = trunc(math:sqrt(M)), | |
IS = (((I-1) div K) * K) + 1, | |
JS = (((I-1) rem K) * K) + 1, | |
SL = lists:sublist(S, IS, K), | |
lists:flatten(transpose([lists:sublist(L, JS, K) || L <- SL])). | |
transpose([[]|_]) -> []; | |
transpose(M) -> | |
[lists:map(fun hd/1, M) | transpose(lists:map(fun tl/1, M))]. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment