Skip to content

Instantly share code, notes, and snippets.

@najibghadri
Created October 17, 2017 22:24
Show Gist options
  • Save najibghadri/bd9f8c8aab78ae9497a1ec5e6a32fa1d to your computer and use it in GitHub Desktop.
Save najibghadri/bd9f8c8aab78ae9497a1ec5e6a32fa1d to your computer and use it in GitHub Desktop.
-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