Sha256: 2c5d3febbba296ad4b76bd113ad11b97f638f2994993494d5a1ce88190f2ecf4
Contents?: true
Size: 676 Bytes
Versions: 69
Compression:
Stored size: 676 Bytes
Contents
defmodule CryptoSquare do @doc """ Encode string square methods ## Examples iex> CryptoSquare.encode("abcd") "ac bd" """ @spec encode(String.t()) :: String.t() def encode(""), do: "" def encode(str) do normalized = normalize_string(str) section_length = normalized |> byte_size |> :math.sqrt() |> Float.ceil() |> trunc normalized |> String.graphemes() |> Enum.chunk(section_length, section_length, List.duplicate("", section_length)) |> List.zip() |> Enum.map(&Tuple.to_list/1) |> Enum.join(" ") end defp normalize_string(str) do str |> String.downcase() |> String.replace(~r/[^a-z0-9]/, "") end end
Version data entries
69 entries across 69 versions & 1 rubygems