Skip to content

Instantly share code, notes, and snippets.

@frobs
Created January 17, 2023 11:38
Show Gist options
  • Save frobs/278190b8090bc817c6ff524dc33de830 to your computer and use it in GitHub Desktop.
Save frobs/278190b8090bc817c6ff524dc33de830 to your computer and use it in GitHub Desktop.
defmodule MyTestScript do
@h 7
@fixed_value 37
def decode(num) do
decode_internal(num, "")
end
defp decode_internal(num, accum) when num == @h do
String.reverse(accum)
end
defp decode_internal(num, accum) do
conversion_table = %{3 => "e", 1 => "c", 6 => "i", 9 => "n"}
value = rem(num, @fixed_value)
next_num = get_next_num(num, value)
decode_internal(next_num, accum <> Map.get(conversion_table, value))
end
defp get_next_num(num, subtraction) do
trunc((num - subtraction) / @fixed_value)
end
end
IO.puts(MyTestScript.decode(13583258))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment